<?php

namespace Nur\Hash;

class Hash implements HashInterface
{
    /**
     * Get information about the given hashed value.
     *
     * @param  string $hashedValue
     *
     * @return array
     */
    public function info($hashedValue)
    {
        return $this->driver()->info($hashedValue);
    }

    /**
     * Hash the given value.
     *
     * @param  string $value
     * @param  array  $options
     *
     * @return string
     */
    public function make($value, array $options = [])
    {
        return $this->driver()->make($value, $options);
    }

    /**
     * Check the given plain value against a hash.
     *
     * @param  string $value
     * @param  string $hashedValue
     * @param  array  $options
     *
     * @return bool
     */
    public function check($value, $hashedValue, array $options = [])
    {
        return $this->driver()->check($value, $hashedValue, $options);
    }

    /**
     * Check if the given hash has been hashed using the given options.
     *
     * @param  string $hashedValue
     * @param  array  $options
     *
     * @return bool
     */
    public function needsRehash($hashedValue, array $options = [])
    {
        return $this->driver()->needsRehash($hashedValue, $options);
    }

    /**
     * Get the default driver name.
     *
     * @return string
     */
    public function getDefaultDriver()
    {
        return config('hashing.driver') ?? 'bcrypt';
    }

    /**
     * Get the default driver.
     *
     * @return mixed
     */
    protected function driver()
    {
        if ($this->getDefaultDriver() === 'argon') {
            return $this->createArgonDriver();
        } elseif ($this->getDefaultDriver() === 'argon2id') {
            return $this->createArgon2IdDriver();
        }

        return $this->createBcryptDriver();
    }

    /**
     * Create an instance of the Bcrypt hash Driver.
     *
     * @return \Nur\Hash\BcryptHash
     */
    public function createBcryptDriver()
    {
        return new BcryptHash(config('hashing.bcrypt') ?? []);
    }

    /**
     * Create an instance of the Argon2 hash Driver.
     *
     * @return \Nur\Hash\ArgonHash
     */
    public function createArgonDriver()
    {
        return new ArgonHash(config('hashing.argon') ?? []);
    }

    /**
     * Create an instance of the Argon2 hash Driver.
     *
     * @return \Nur\Hash\ArgonHash
     */
    public function createArgon2IdDriver()
    {
        return new Argon2IdHash(config('hashing.argon') ?? []);
    }
}


<?php
/**
 * TaskAttributes
 *
 * PHP version 5
 *
 * @category Class
 * @package  ProcessMaker\PMIO
 * @author   http://github.com/swagger-api/swagger-codegen
 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
 * @link     https://github.com/swagger-api/swagger-codegen
 */

/**
 * ProcessMaker API
 *
 * This ProcessMaker I/O API provides access to a BPMN 2.0 compliant workflow engine API that is designed to be used as a microservice to support enterprise cloud applications. The current Alpha 1.0 version supports most of the descriptive classes of the BPMN 2.0 specification.
 *
 * OpenAPI spec version: 1.0.0
 * Contact: support@processmaker.io
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen
 * Do not edit the class manually.
 */

namespace ProcessMaker\PMIO\Model;

use \ArrayAccess;

/**
 * TaskAttributes Class Doc Comment
 *
 * @category    Class */
/**
 * @package     ProcessMaker\PMIO
 * @author      http://github.com/swagger-api/swagger-codegen
 * @license     http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
 * @link        https://github.com/swagger-api/swagger-codegen
 */
class TaskAttributes implements ArrayAccess
{
    /**
      * The original name of the model.
      * @var string
      */
    protected static $swaggerModelName = 'Task_attributes';

    /**
      * Array of property to type mappings. Used for (de)serialization
      * @var string[]
      */
    protected static $swaggerTypes = array(
        'name' => 'string',
        'description' => 'string',
        'process_id' => 'string',
        'type' => 'string',
        'assign_type' => 'string',
        'last_assigned_user_id' => 'string',
        'script' => 'string',
        'ref_id' => 'string',
        'created_at' => 'string',
        'updated_at' => 'string'
    );

    public static function swaggerTypes()
    {
        return self::$swaggerTypes;
    }

    /**
     * Array of attributes where the key is the local name, and the value is the original name
     * @var string[]
     */
    protected static $attributeMap = array(
        'name' => 'name',
        'description' => 'description',
        'process_id' => 'process_id',
        'type' => 'type',
        'assign_type' => 'assign_type',
        'last_assigned_user_id' => 'last_assigned_user_id',
        'script' => 'script',
        'ref_id' => 'ref_id',
        'created_at' => 'created_at',
        'updated_at' => 'updated_at'
    );

    public static function attributeMap()
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     * @var string[]
     */
    protected static $setters = array(
        'name' => 'setName',
        'description' => 'setDescription',
        'process_id' => 'setProcessId',
        'type' => 'setType',
        'assign_type' => 'setAssignType',
        'last_assigned_user_id' => 'setLastAssignedUserId',
        'script' => 'setScript',
        'ref_id' => 'setRefId',
        'created_at' => 'setCreatedAt',
        'updated_at' => 'setUpdatedAt'
    );

    public static function setters()
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests)
     * @var string[]
     */
    protected static $getters = array(
        'name' => 'getName',
        'description' => 'getDescription',
        'process_id' => 'getProcessId',
        'type' => 'getType',
        'assign_type' => 'getAssignType',
        'last_assigned_user_id' => 'getLastAssignedUserId',
        'script' => 'getScript',
        'ref_id' => 'getRefId',
        'created_at' => 'getCreatedAt',
        'updated_at' => 'getUpdatedAt'
    );

    public static function getters()
    {
        return self::$getters;
    }

    const TYPE_NORMAL = 'NORMAL';
    const TYPE_ADHOC = 'ADHOC';
    const TYPE_SUBPROCESS = 'SUBPROCESS';
    const TYPE_HIDDEN = 'HIDDEN';
    const TYPE_GATEWAYTOGATEWAY = 'GATEWAYTOGATEWAY';
    const TYPE_WEBENTRYEVENT = 'WEBENTRYEVENT';
    const TYPE_END_MESSAGE_EVENT = 'END-MESSAGE-EVENT';
    const TYPE_START_MESSAGE_EVENT = 'START-MESSAGE-EVENT';
    const TYPE_INTERMEDIATE_THROW_MESSAGE_EVENT = 'INTERMEDIATE-THROW-MESSAGE-EVENT';
    const TYPE_INTERMEDIATE_CATCH_MESSAGE_EVENT = 'INTERMEDIATE-CATCH-MESSAGE-EVENT';
    const TYPE_SCRIPT_TASK = 'SCRIPT-TASK';
    const TYPE_SERVICE_TASK = 'SERVICE-TASK';
    const TYPE_USER_TASK = 'USER-TASK';
    const TYPE_START_TIMER_EVENT = 'START-TIMER-EVENT';
    const TYPE_INTERMEDIATE_CATCH_TIMER_EVENT = 'INTERMEDIATE-CATCH-TIMER-EVENT';
    const TYPE_END_EMAIL_EVENT = 'END-EMAIL-EVENT';
    const TYPE_INTERMEDIATE_THROW_EMAIL_EVENT = 'INTERMEDIATE-THROW-EMAIL-EVENT';
    const ASSIGN_TYPE_CYCLIC = 'CYCLIC';
    const ASSIGN_TYPE_MANUAL = 'MANUAL';
    const ASSIGN_TYPE_EVALUATE = 'EVALUATE';
    const ASSIGN_TYPE_REPORT_TO = 'REPORT_TO';
    const ASSIGN_TYPE_SELF_SERVICE = 'SELF_SERVICE';
    const ASSIGN_TYPE_STATIC_MI = 'STATIC_MI';
    const ASSIGN_TYPE_CANCEL_MI = 'CANCEL_MI';
    const ASSIGN_TYPE_MULTIPLE_INSTANCE = 'MULTIPLE_INSTANCE';
    const ASSIGN_TYPE_MULTIPLE_INSTANCE_VALUE_BASED = 'MULTIPLE_INSTANCE_VALUE_BASED';

    /**
     * Gets allowable values of the enum
     * @return string[]
     */
    public function getTypeAllowableValues()
    {
        return [
            self::TYPE_NORMAL,
            self::TYPE_ADHOC,
            self::TYPE_SUBPROCESS,
            self::TYPE_HIDDEN,
            self::TYPE_GATEWAYTOGATEWAY,
            self::TYPE_WEBENTRYEVENT,
            self::TYPE_END_MESSAGE_EVENT,
            self::TYPE_START_MESSAGE_EVENT,
            self::TYPE_INTERMEDIATE_THROW_MESSAGE_EVENT,
            self::TYPE_INTERMEDIATE_CATCH_MESSAGE_EVENT,
            self::TYPE_SCRIPT_TASK,
            self::TYPE_SERVICE_TASK,
            self::TYPE_USER_TASK,
            self::TYPE_START_TIMER_EVENT,
            self::TYPE_INTERMEDIATE_CATCH_TIMER_EVENT,
            self::TYPE_END_EMAIL_EVENT,
            self::TYPE_INTERMEDIATE_THROW_EMAIL_EVENT,
        ];
    }

    /**
     * Gets allowable values of the enum
     * @return string[]
     */
    public function getAssignTypeAllowableValues()
    {
        return [
            self::ASSIGN_TYPE_CYCLIC,
            self::ASSIGN_TYPE_MANUAL,
            self::ASSIGN_TYPE_EVALUATE,
            self::ASSIGN_TYPE_REPORT_TO,
            self::ASSIGN_TYPE_SELF_SERVICE,
            self::ASSIGN_TYPE_STATIC_MI,
            self::ASSIGN_TYPE_CANCEL_MI,
            self::ASSIGN_TYPE_MULTIPLE_INSTANCE,
            self::ASSIGN_TYPE_MULTIPLE_INSTANCE_VALUE_BASED,
        ];
    }

    /**
     * Associative array for storing property values
     * @var mixed[]
     */
    protected $container = array();

    /**
     * Constructor
     * @param mixed[] $data Associated array of property value initalizing the model
     */
    public function __construct(array $data = null)
    {
        $this->container['name'] = isset($data['name']) ? $data['name'] : null;
        $this->container['description'] = isset($data['description']) ? $data['description'] : null;
        $this->container['process_id'] = isset($data['process_id']) ? $data['process_id'] : null;
        $this->container['type'] = isset($data['type']) ? $data['type'] : 'NORMAL';
        $this->container['assign_type'] = isset($data['assign_type']) ? $data['assign_type'] : 'CYCLIC';
        $this->container['last_assigned_user_id'] = isset($data['last_assigned_user_id']) ? $data['last_assigned_user_id'] : null;
        $this->container['script'] = isset($data['script']) ? $data['script'] : null;
        $this->container['ref_id'] = isset($data['ref_id']) ? $data['ref_id'] : null;
        $this->container['created_at'] = isset($data['created_at']) ? $data['created_at'] : null;
        $this->container['updated_at'] = isset($data['updated_at']) ? $data['updated_at'] : null;
    }

    /**
     * show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties()
    {
        $invalid_properties = array();
        if ($this->container['name'] === null) {
            $invalid_properties[] = "'name' can't be null";
        }
        if ($this->container['process_id'] === null) {
            $invalid_properties[] = "'process_id' can't be null";
        }
        if ($this->container['type'] === null) {
            $invalid_properties[] = "'type' can't be null";
        }
        $allowed_values = array("NORMAL", "ADHOC", "SUBPROCESS", "HIDDEN", "GATEWAYTOGATEWAY", "WEBENTRYEVENT", "END-MESSAGE-EVENT", "START-MESSAGE-EVENT", "INTERMEDIATE-THROW-MESSAGE-EVENT", "INTERMEDIATE-CATCH-MESSAGE-EVENT", "SCRIPT-TASK", "SERVICE-TASK", "USER-TASK", "START-TIMER-EVENT", "INTERMEDIATE-CATCH-TIMER-EVENT", "END-EMAIL-EVENT", "INTERMEDIATE-THROW-EMAIL-EVENT");
        if (!in_array($this->container['type'], $allowed_values)) {
            $invalid_properties[] = "invalid value for 'type', must be one of #{allowed_values}.";
        }

        if ($this->container['assign_type'] === null) {
            $invalid_properties[] = "'assign_type' can't be null";
        }
        $allowed_values = array("CYCLIC", "MANUAL", "EVALUATE", "REPORT_TO", "SELF_SERVICE", "STATIC_MI", "CANCEL_MI", "MULTIPLE_INSTANCE", "MULTIPLE_INSTANCE_VALUE_BASED");
        if (!in_array($this->container['assign_type'], $allowed_values)) {
            $invalid_properties[] = "invalid value for 'assign_type', must be one of #{allowed_values}.";
        }

        if (!is_null($this->container['ref_id']) && (strlen($this->container['ref_id']) > 255)) {
            $invalid_properties[] = "invalid value for 'ref_id', the character length must be smaller than or equal to 255.";
        }

        return $invalid_properties;
    }

    /**
     * validate all the properties in the model
     * return true if all passed
     *
     * @return bool True if all properteis are valid
     */
    public function valid()
    {
        if ($this->container['name'] === null) {
            return false;
        }
        if ($this->container['process_id'] === null) {
            return false;
        }
        if ($this->container['type'] === null) {
            return false;
        }
        $allowed_values = array("NORMAL", "ADHOC", "SUBPROCESS", "HIDDEN", "GATEWAYTOGATEWAY", "WEBENTRYEVENT", "END-MESSAGE-EVENT", "START-MESSAGE-EVENT", "INTERMEDIATE-THROW-MESSAGE-EVENT", "INTERMEDIATE-CATCH-MESSAGE-EVENT", "SCRIPT-TASK", "SERVICE-TASK", "USER-TASK", "START-TIMER-EVENT", "INTERMEDIATE-CATCH-TIMER-EVENT", "END-EMAIL-EVENT", "INTERMEDIATE-THROW-EMAIL-EVENT");
        if (!in_array($this->container['type'], $allowed_values)) {
            return false;
        }
        if ($this->container['assign_type'] === null) {
            return false;
        }
        $allowed_values = array("CYCLIC", "MANUAL", "EVALUATE", "REPORT_TO", "SELF_SERVICE", "STATIC_MI", "CANCEL_MI", "MULTIPLE_INSTANCE", "MULTIPLE_INSTANCE_VALUE_BASED");
        if (!in_array($this->container['assign_type'], $allowed_values)) {
            return false;
        }
        if (strlen($this->container['ref_id']) > 255) {
            return false;
        }
        return true;
    }

    /**
     * Gets name
     * @return string
     */
    public function getName()
    {
        return $this->container['name'];
    }

    /**
     * Sets name
     * @param string $name
     * @return $this
     */
    public function setName($name)
    {
        $this->container['name'] = $name;

        return $this;
    }

    /**
     * Gets description
     * @return string
     */
    public function getDescription()
    {
        return $this->container['description'];
    }

    /**
     * Sets description
     * @param string $description
     * @return $this
     */
    public function setDescription($description)
    {
        $this->container['description'] = $description;

        return $this;
    }

    /**
     * Gets process_id
     * @return string
     */
    public function getProcessId()
    {
        return $this->container['process_id'];
    }

    /**
     * Sets process_id
     * @param string $process_id
     * @return $this
     */
    public function setProcessId($process_id)
    {
        $this->container['process_id'] = $process_id;

        return $this;
    }

    /**
     * Gets type
     * @return string
     */
    public function getType()
    {
        return $this->container['type'];
    }

    /**
     * Sets type
     * @param string $type
     * @return $this
     */
    public function setType($type)
    {
        $allowed_values = array('NORMAL', 'ADHOC', 'SUBPROCESS', 'HIDDEN', 'GATEWAYTOGATEWAY', 'WEBENTRYEVENT', 'END-MESSAGE-EVENT', 'START-MESSAGE-EVENT', 'INTERMEDIATE-THROW-MESSAGE-EVENT', 'INTERMEDIATE-CATCH-MESSAGE-EVENT', 'SCRIPT-TASK', 'SERVICE-TASK', 'USER-TASK', 'START-TIMER-EVENT', 'INTERMEDIATE-CATCH-TIMER-EVENT', 'END-EMAIL-EVENT', 'INTERMEDIATE-THROW-EMAIL-EVENT');
        if (!in_array($type, $allowed_values)) {
            throw new \InvalidArgumentException("Invalid value for 'type', must be one of 'NORMAL', 'ADHOC', 'SUBPROCESS', 'HIDDEN', 'GATEWAYTOGATEWAY', 'WEBENTRYEVENT', 'END-MESSAGE-EVENT', 'START-MESSAGE-EVENT', 'INTERMEDIATE-THROW-MESSAGE-EVENT', 'INTERMEDIATE-CATCH-MESSAGE-EVENT', 'SCRIPT-TASK', 'SERVICE-TASK', 'USER-TASK', 'START-TIMER-EVENT', 'INTERMEDIATE-CATCH-TIMER-EVENT', 'END-EMAIL-EVENT', 'INTERMEDIATE-THROW-EMAIL-EVENT'");
        }
        $this->container['type'] = $type;

        return $this;
    }

    /**
     * Gets assign_type
     * @return string
     */
    public function getAssignType()
    {
        return $this->container['assign_type'];
    }

    /**
     * Sets assign_type
     * @param string $assign_type
     * @return $this
     */
    public function setAssignType($assign_type)
    {
        $allowed_values = array('CYCLIC', 'MANUAL', 'EVALUATE', 'REPORT_TO', 'SELF_SERVICE', 'STATIC_MI', 'CANCEL_MI', 'MULTIPLE_INSTANCE', 'MULTIPLE_INSTANCE_VALUE_BASED');
        if (!in_array($assign_type, $allowed_values)) {
            throw new \InvalidArgumentException("Invalid value for 'assign_type', must be one of 'CYCLIC', 'MANUAL', 'EVALUATE', 'REPORT_TO', 'SELF_SERVICE', 'STATIC_MI', 'CANCEL_MI', 'MULTIPLE_INSTANCE', 'MULTIPLE_INSTANCE_VALUE_BASED'");
        }
        $this->container['assign_type'] = $assign_type;

        return $this;
    }

    /**
     * Gets last_assigned_user_id
     * @return string
     */
    public function getLastAssignedUserId()
    {
        return $this->container['last_assigned_user_id'];
    }

    /**
     * Sets last_assigned_user_id
     * @param string $last_assigned_user_id
     * @return $this
     */
    public function setLastAssignedUserId($last_assigned_user_id)
    {
        $this->container['last_assigned_user_id'] = $last_assigned_user_id;

        return $this;
    }

    /**
     * Gets script
     * @return string
     */
    public function getScript()
    {
        return $this->container['script'];
    }

    /**
     * Sets script
     * @param string $script
     * @return $this
     */
    public function setScript($script)
    {
        $this->container['script'] = $script;

        return $this;
    }

    /**
     * Gets ref_id
     * @return string
     */
    public function getRefId()
    {
        return $this->container['ref_id'];
    }

    /**
     * Sets ref_id
     * @param string $ref_id Set as XML object ID if imported from BPMN file or can be optionally set when object added via API. Used to optionally refer object by ref_id instead of using its UUID.
     * @return $this
     */
    public function setRefId($ref_id)
    {
        if (strlen($ref_id) > 255) {
            throw new \InvalidArgumentException('invalid length for $ref_id when calling TaskAttributes., must be smaller than or equal to 255.');
        }
        $this->container['ref_id'] = $ref_id;

        return $this;
    }

    /**
     * Gets created_at
     * @return string
     */
    public function getCreatedAt()
    {
        return $this->container['created_at'];
    }

    /**
     * Sets created_at
     * @param string $created_at
     * @return $this
     */
    public function setCreatedAt($created_at)
    {
        $this->container['created_at'] = $created_at;

        return $this;
    }

    /**
     * Gets updated_at
     * @return string
     */
    public function getUpdatedAt()
    {
        return $this->container['updated_at'];
    }

    /**
     * Sets updated_at
     * @param string $updated_at
     * @return $this
     */
    public function setUpdatedAt($updated_at)
    {
        $this->container['updated_at'] = $updated_at;

        return $this;
    }
    /**
     * Returns true if offset exists. False otherwise.
     * @param  integer $offset Offset
     * @return boolean
     */
    public function offsetExists($offset)
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     * @param  integer $offset Offset
     * @return mixed
     */
    public function offsetGet($offset)
    {
        return isset($this->container[$offset]) ? $this->container[$offset] : null;
    }

    /**
     * Sets value based on offset.
     * @param  integer $offset Offset
     * @param  mixed   $value  Value to be set
     * @return void
     */
    public function offsetSet($offset, $value)
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     * @param  integer $offset Offset
     * @return void
     */
    public function offsetUnset($offset)
    {
        unset($this->container[$offset]);
    }

    /**
     * Gets the string presentation of the object
     * @return string
     */
    public function __toString()
    {
        if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print
            return json_encode(\ProcessMaker\PMIO\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT);
        }

        return json_encode(\ProcessMaker\PMIO\ObjectSerializer::sanitizeForSerialization($this));
    }
}


<?php
/**
 * GatewayAttributes
 *
 * PHP version 5
 *
 * @category Class
 * @package  ProcessMaker\PMIO
 * @author   http://github.com/swagger-api/swagger-codegen
 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
 * @link     https://github.com/swagger-api/swagger-codegen
 */

/**
 * ProcessMaker API
 *
 * This ProcessMaker I/O API provides access to a BPMN 2.0 compliant workflow engine API that is designed to be used as a microservice to support enterprise cloud applications. The current Alpha 1.0 version supports most of the descriptive classes of the BPMN 2.0 specification.
 *
 * OpenAPI spec version: 1.0.0
 * Contact: support@processmaker.io
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen
 * Do not edit the class manually.
 */

namespace ProcessMaker\PMIO\Model;

use \ArrayAccess;

/**
 * GatewayAttributes Class Doc Comment
 *
 * @category    Class */
/**
 * @package     ProcessMaker\PMIO
 * @author      http://github.com/swagger-api/swagger-codegen
 * @license     http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
 * @link        https://github.com/swagger-api/swagger-codegen
 */
class GatewayAttributes implements ArrayAccess
{
    /**
      * The original name of the model.
      * @var string
      */
    protected static $swaggerModelName = 'Gateway_attributes';

    /**
      * Array of property to type mappings. Used for (de)serialization
      * @var string[]
      */
    protected static $swaggerTypes = array(
        'name' => 'string',
        'description' => 'string',
        'process_id' => 'string',
        'type' => 'string',
        'direction' => 'string',
        'ref_id' => 'string',
        'created_at' => 'string',
        'updated_at' => 'string'
    );

    public static function swaggerTypes()
    {
        return self::$swaggerTypes;
    }

    /**
     * Array of attributes where the key is the local name, and the value is the original name
     * @var string[]
     */
    protected static $attributeMap = array(
        'name' => 'name',
        'description' => 'description',
        'process_id' => 'process_id',
        'type' => 'type',
        'direction' => 'direction',
        'ref_id' => 'ref_id',
        'created_at' => 'created_at',
        'updated_at' => 'updated_at'
    );

    public static function attributeMap()
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     * @var string[]
     */
    protected static $setters = array(
        'name' => 'setName',
        'description' => 'setDescription',
        'process_id' => 'setProcessId',
        'type' => 'setType',
        'direction' => 'setDirection',
        'ref_id' => 'setRefId',
        'created_at' => 'setCreatedAt',
        'updated_at' => 'setUpdatedAt'
    );

    public static function setters()
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests)
     * @var string[]
     */
    protected static $getters = array(
        'name' => 'getName',
        'description' => 'getDescription',
        'process_id' => 'getProcessId',
        'type' => 'getType',
        'direction' => 'getDirection',
        'ref_id' => 'getRefId',
        'created_at' => 'getCreatedAt',
        'updated_at' => 'getUpdatedAt'
    );

    public static function getters()
    {
        return self::$getters;
    }

    const TYPE_EXCLUSIVE = 'EXCLUSIVE';
    const TYPE_INCLUSIVE = 'INCLUSIVE';
    const TYPE_PARALLEL = 'PARALLEL';
    const TYPE_EVENT = 'EVENT';
    const DIRECTION_DIVERGENT = 'DIVERGENT';
    const DIRECTION_CONVERGENT = 'CONVERGENT';
    const DIRECTION_MIXED = 'MIXED';

    /**
     * Gets allowable values of the enum
     * @return string[]
     */
    public function getTypeAllowableValues()
    {
        return [
            self::TYPE_EXCLUSIVE,
            self::TYPE_INCLUSIVE,
            self::TYPE_PARALLEL,
            self::TYPE_EVENT,
        ];
    }

    /**
     * Gets allowable values of the enum
     * @return string[]
     */
    public function getDirectionAllowableValues()
    {
        return [
            self::DIRECTION_DIVERGENT,
            self::DIRECTION_CONVERGENT,
            self::DIRECTION_MIXED,
        ];
    }

    /**
     * Associative array for storing property values
     * @var mixed[]
     */
    protected $container = array();

    /**
     * Constructor
     * @param mixed[] $data Associated array of property value initalizing the model
     */
    public function __construct(array $data = null)
    {
        $this->container['name'] = isset($data['name']) ? $data['name'] : null;
        $this->container['description'] = isset($data['description']) ? $data['description'] : null;
        $this->container['process_id'] = isset($data['process_id']) ? $data['process_id'] : null;
        $this->container['type'] = isset($data['type']) ? $data['type'] : null;
        $this->container['direction'] = isset($data['direction']) ? $data['direction'] : null;
        $this->container['ref_id'] = isset($data['ref_id']) ? $data['ref_id'] : null;
        $this->container['created_at'] = isset($data['created_at']) ? $data['created_at'] : null;
        $this->container['updated_at'] = isset($data['updated_at']) ? $data['updated_at'] : null;
    }

    /**
     * show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties()
    {
        $invalid_properties = array();
        if ($this->container['process_id'] === null) {
            $invalid_properties[] = "'process_id' can't be null";
        }
        if ($this->container['type'] === null) {
            $invalid_properties[] = "'type' can't be null";
        }
        $allowed_values = array("EXCLUSIVE", "INCLUSIVE", "PARALLEL", "EVENT");
        if (!in_array($this->container['type'], $allowed_values)) {
            $invalid_properties[] = "invalid value for 'type', must be one of #{allowed_values}.";
        }

        $allowed_values = array("DIVERGENT", "CONVERGENT", "MIXED");
        if (!in_array($this->container['direction'], $allowed_values)) {
            $invalid_properties[] = "invalid value for 'direction', must be one of #{allowed_values}.";
        }

        if (!is_null($this->container['ref_id']) && (strlen($this->container['ref_id']) > 255)) {
            $invalid_properties[] = "invalid value for 'ref_id', the character length must be smaller than or equal to 255.";
        }

        return $invalid_properties;
    }

    /**
     * validate all the properties in the model
     * return true if all passed
     *
     * @return bool True if all properteis are valid
     */
    public function valid()
    {
        if ($this->container['process_id'] === null) {
            return false;
        }
        if ($this->container['type'] === null) {
            return false;
        }
        $allowed_values = array("EXCLUSIVE", "INCLUSIVE", "PARALLEL", "EVENT");
        if (!in_array($this->container['type'], $allowed_values)) {
            return false;
        }
        $allowed_values = array("DIVERGENT", "CONVERGENT", "MIXED");
        if (!in_array($this->container['direction'], $allowed_values)) {
            return false;
        }
        if (strlen($this->container['ref_id']) > 255) {
            return false;
        }
        return true;
    }

    /**
     * Gets name
     * @return string
     */
    public function getName()
    {
        return $this->container['name'];
    }

    /**
     * Sets name
     * @param string $name
     * @return $this
     */
    public function setName($name)
    {
        $this->container['name'] = $name;

        return $this;
    }

    /**
     * Gets description
     * @return string
     */
    public function getDescription()
    {
        return $this->container['description'];
    }

    /**
     * Sets description
     * @param string $description
     * @return $this
     */
    public function setDescription($description)
    {
        $this->container['description'] = $description;

        return $this;
    }

    /**
     * Gets process_id
     * @return string
     */
    public function getProcessId()
    {
        return $this->container['process_id'];
    }

    /**
     * Sets process_id
     * @param string $process_id
     * @return $this
     */
    public function setProcessId($process_id)
    {
        $this->container['process_id'] = $process_id;

        return $this;
    }

    /**
     * Gets type
     * @return string
     */
    public function getType()
    {
        return $this->container['type'];
    }

    /**
     * Sets type
     * @param string $type
     * @return $this
     */
    public function setType($type)
    {
        $allowed_values = array('EXCLUSIVE', 'INCLUSIVE', 'PARALLEL', 'EVENT');
        if (!in_array($type, $allowed_values)) {
            throw new \InvalidArgumentException("Invalid value for 'type', must be one of 'EXCLUSIVE', 'INCLUSIVE', 'PARALLEL', 'EVENT'");
        }
        $this->container['type'] = $type;

        return $this;
    }

    /**
     * Gets direction
     * @return string
     */
    public function getDirection()
    {
        return $this->container['direction'];
    }

    /**
     * Sets direction
     * @param string $direction
     * @return $this
     */
    public function setDirection($direction)
    {
        $allowed_values = array('DIVERGENT', 'CONVERGENT', 'MIXED');
        if (!in_array($direction, $allowed_values)) {
            throw new \InvalidArgumentException("Invalid value for 'direction', must be one of 'DIVERGENT', 'CONVERGENT', 'MIXED'");
        }
        $this->container['direction'] = $direction;

        return $this;
    }

    /**
     * Gets ref_id
     * @return string
     */
    public function getRefId()
    {
        return $this->container['ref_id'];
    }

    /**
     * Sets ref_id
     * @param string $ref_id Set as XML object ID if imported from BPMN file or can be optionally set when object added via API. Used to optionally refer object by ref_id instead of using its UUID.
     * @return $this
     */
    public function setRefId($ref_id)
    {
        if (strlen($ref_id) > 255) {
            throw new \InvalidArgumentException('invalid length for $ref_id when calling GatewayAttributes., must be smaller than or equal to 255.');
        }
        $this->container['ref_id'] = $ref_id;

        return $this;
    }

    /**
     * Gets created_at
     * @return string
     */
    public function getCreatedAt()
    {
        return $this->container['created_at'];
    }

    /**
     * Sets created_at
     * @param string $created_at
     * @return $this
     */
    public function setCreatedAt($created_at)
    {
        $this->container['created_at'] = $created_at;

        return $this;
    }

    /**
     * Gets updated_at
     * @return string
     */
    public function getUpdatedAt()
    {
        return $this->container['updated_at'];
    }

    /**
     * Sets updated_at
     * @param string $updated_at
     * @return $this
     */
    public function setUpdatedAt($updated_at)
    {
        $this->container['updated_at'] = $updated_at;

        return $this;
    }
    /**
     * Returns true if offset exists. False otherwise.
     * @param  integer $offset Offset
     * @return boolean
     */
    public function offsetExists($offset)
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     * @param  integer $offset Offset
     * @return mixed
     */
    public function offsetGet($offset)
    {
        return isset($this->container[$offset]) ? $this->container[$offset] : null;
    }

    /**
     * Sets value based on offset.
     * @param  integer $offset Offset
     * @param  mixed   $value  Value to be set
     * @return void
     */
    public function offsetSet($offset, $value)
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     * @param  integer $offset Offset
     * @return void
     */
    public function offsetUnset($offset)
    {
        unset($this->container[$offset]);
    }

    /**
     * Gets the string presentation of the object
     * @return string
     */
    public function __toString()
    {
        if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print
            return json_encode(\ProcessMaker\PMIO\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT);
        }

        return json_encode(\ProcessMaker\PMIO\ObjectSerializer::sanitizeForSerialization($this));
    }
}


<?php

namespace Nur\Kernel;

class AliasLoader
{
    /**
     * The array of class aliases.
     *
     * @var array
     */
    protected $aliases;

    /**
     * Indicates if a loader has been registered.
     *
     * @var bool
     */
    protected $registered = false;

    /**
     * The namespace for all real-time facades.
     *
     * @var string
     */
    protected static $facadeNamespace = 'Facades\\';

    /**
     * The singleton instance of the loader.
     *
     * @var \Nur\Kernel\AliasLoader
     */
    protected static $instance;

    /**
     * Create a new AliasLoader instance.
     *
     * @param  array  $aliases
     * @return void
     */
    private function __construct($aliases)
    {
        $this->aliases = $aliases;
    }

    /**
     * Get or create the singleton alias loader instance.
     *
     * @param  array  $aliases
     * @return \Nur\Kernel\AliasLoader
     */
    public static function getInstance(array $aliases = [])
    {
        if (is_null(static::$instance)) {
            return static::$instance = new static($aliases);
        }

        $aliases = array_merge(static::$instance->getAliases(), $aliases);

        static::$instance->setAliases($aliases);

        return static::$instance;
    }

    /**
     * Load a class alias if it is registered.
     *
     * @param  string  $alias
     * @return bool|null
     */
    public function load($alias)
    {
        if (static::$facadeNamespace && strpos($alias, static::$facadeNamespace) === 0) {
            $this->loadFacade($alias);

            return true;
        }

        if (isset($this->aliases[$alias])) {
            return class_alias($this->aliases[$alias], $alias);
        }
    }

    /**
     * Load a real-time facade for the given alias.
     *
     * @param  string  $alias
     * @return void
     */
    protected function loadFacade($alias)
    {
        require $this->ensureFacadeExists($alias);
    }

    /**
     * Ensure that the given alias has an existing real-time facade class.
     *
     * @param  string  $alias
     * @return string
     */
    protected function ensureFacadeExists($alias)
    {
        if (file_exists($path = storage_path('cache/facade-'.sha1($alias).'.php'))) {
            return $path;
        }

        file_put_contents($path, $this->formatFacadeStub(
            $alias, file_get_contents(__DIR__.'/stubs/facade.stub')
        ));

        return $path;
    }

    /**
     * Format the facade stub with the proper namespace and class.
     *
     * @param  string  $alias
     * @param  string  $stub
     * @return string
     */
    protected function formatFacadeStub($alias, $stub)
    {
        $replacements = [
            str_replace('/', '\\', dirname(str_replace('\\', '/', $alias))),
            class_basename($alias),
            substr($alias, strlen(static::$facadeNamespace)),
        ];

        return str_replace(
            ['DummyNamespace', 'DummyClass', 'DummyTarget'], $replacements, $stub
        );
    }

    /**
     * Add an alias to the loader.
     *
     * @param  string  $class
     * @param  string  $alias
     * @return void
     */
    public function alias($class, $alias)
    {
        $this->aliases[$class] = $alias;
    }

    /**
     * Register the loader on the auto-loader stack.
     *
     * @return void
     */
    public function register()
    {
        if (! $this->registered) {
            $this->prependToLoaderStack();

            $this->registered = true;
        }
    }

    /**
     * Prepend the load method to the auto-loader stack.
     *
     * @return void
     */
    protected function prependToLoaderStack()
    {
        spl_autoload_register([$this, 'load'], true, true);
    }

    /**
     * Get the registered aliases.
     *
     * @return array
     */
    public function getAliases()
    {
        return $this->aliases;
    }

    /**
     * Set the registered aliases.
     *
     * @param  array  $aliases
     * @return void
     */
    public function setAliases(array $aliases)
    {
        $this->aliases = $aliases;
    }

    /**
     * Indicates if the loader has been registered.
     *
     * @return bool
     */
    public function isRegistered()
    {
        return $this->registered;
    }

    /**
     * Set the "registered" state of the loader.
     *
     * @param  bool  $value
     * @return void
     */
    public function setRegistered($value)
    {
        $this->registered = $value;
    }

    /**
     * Set the real-time facade namespace.
     *
     * @param  string  $namespace
     * @return void
     */
    public static function setFacadeNamespace($namespace)
    {
        static::$facadeNamespace = rtrim($namespace, '\\').'\\';
    }

    /**
     * Set the value of the singleton alias loader.
     *
     * @param  \Nur\Kernel\AliasLoader  $loader
     * @return void
     */
    public static function setInstance($loader)
    {
        static::$instance = $loader;
    }

    /**
     * Clone method.
     *
     * @return void
     */
    private function __clone()
    {
        //
    }
}


<?php

namespace Nur\Console\Commands\Migrations;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Config\FileLocator;
use Nur\Console\Commands\Migrations\AbstractCommand;

class MigrateCommand extends AbstractCommand
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        parent::configure();

        $this->setName('migrate')
             ->addOption('--target', '-t', InputArgument::OPTIONAL, 'The version number to migrate to')
             ->setDescription('Run all migrations')
             ->setHelp(<<<EOT
The <info>migrate</info> command runs all available migrations, optionally up to a specific version

<info>migration:migrate</info>
<info>migration:migrate -t 20111018185412</info>

EOT
        );
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->bootstrap($input, $output);

        $container  = $this->getContainer();
        $migrations = $this->getMigrations();
        $versions   = $this->getAdapter()->fetchAll();

        $version = $input->getOption('target');

        ksort($migrations);
        sort($versions);

        if (!empty($versions)) {
            // Get the last run migration number
            $current = end($versions);
        } else {
            $current = 0;
        }

        if (null !== $version) {
            if (0 != $version && !isset($migrations[$version])) {
                return;
            }
        } else {
            $versionNumbers = array_merge($versions, array_keys($migrations));
            if (empty($versionNumbers)) {
                return;
            }

            $version = max($versionNumbers);
        }

        $direction = $version > $current ? 'up' : 'down';
        if ($direction == 'down') {
            /**
             * Run downs first
             */
            krsort($migrations);
            foreach($migrations as $migration) {
                if ($migration->getVersion() <= $version) {
                    break;
                }

                if (in_array($migration->getVersion(), $versions)) {
                    $container['phpmig.migrator']->down($migration);
                }
            }
        }

        ksort($migrations);
        foreach($migrations as $migration) {
            if ($migration->getVersion() > $version) {
                break;
            }

            if (!in_array($migration->getVersion(), $versions)) {
                $container['phpmig.migrator']->up($migration);
            }
        }
    }
}


<?php

namespace Nur\Http;

class Cookie
{
    /**
     * Set cookie method.
     *
     * @param string  $key
     * @param string  $value
     * @param integer $time
     *
     * @return void
     */
    public function set($key, $value, $time = 0)
    {
        if (is_array($key)) {
            foreach ($key as $k => $v) {
                setcookie($k, $v, ($time == 0 ? 0 : time() + $time), '/');
                $_COOKIE[$k] = $v;
            }
        } else {
            setcookie($key, $value, ($time == 0 ? 0 : time() + $time), '/');
            $_COOKIE[$key] = $value;
        }

        return;
    }

    /**
     * Get cookie method.
     *
     * @param string $key
     *
     * @return null|mixed
     */
    public function get($key = null)
    {
        return (is_null($key) ? $_COOKIE : ($this->has($key) ? $_COOKIE[$key] : null));
    }

    /**
     * Cookie has key ?
     *
     * @param string $key
     *
     * @return bool
     */
    public function has($key)
    {
        return isset($_COOKIE[$key]);
    }

    /**
     * Delete cookie method.
     *
     * @param string $key
     *
     * @return void
     */
    public function delete($key)
    {
        if ($this->has($key)) {
            setcookie($key, null, -1, '/');
            unset($_COOKIE[$key]);
        }

        return;
    }

    /**
     * Delete all cookie method.
     *
     * @return void
     */
    public function destroy()
    {
        foreach ($_COOKIE as $key => $value) {
            setcookie($key, null, -1, '/');
            unset($_COOKIE[$key]);
        }

        return;
    }
}


<?php

namespace Nur\Http;

use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

class Response extends SymfonyResponse
{
    /** @var bool $json */
    protected $json = false;

    /**
     * Class constructor
     *
     * @param mixed $content
     * @param int   $status
     * @param array $headers
     *
     * @return void
     */
    public function __construct($content = '', int $status = 200, array $headers = [])
    {
        // Remove all headers
        header_remove();

        parent::__construct($content, $status, $headers);
        $this->setCharset('utf-8');
        $this->headers->set('Content-Type', 'text/html; charset=' . $this->getCharset());
    }

    /**
     * Json response
     *
     * @param array $data
     * @param int   $statusCode
     *
     * @return Response
     */
    public function json(array $data = [], int $statusCode = 200)
    {
        $this->setContent(json_encode($data));
        $this->setStatusCode($statusCode);
        $this->json = true;

        return $this;
    }

    /**
     * Add custom header data in Response
     *
     * @param array|string $key
     * @param string $value
     *
     * @return Response
     */
    public function header($key, $value)
    {
        if (is_array($key) && !empty($key)) {
            foreach ($key as $k => $v) {
                $this->headers->set($k, $v);
            }
        } elseif (is_string($key) && !empty($key)) {
            $this->headers->set($key, $value);
        }
        return $this;
    }

    /**
     * Return view file within Response
     *
     * @param string $view
     * @param array  $data
     *
     * @return Response|void
     */
    public function view($view, array $data = [])
    {
        if (function_exists('app')) {
            $this->setContent(
                app('load')->view($view, $data)
            );

            return $this;
        }

        return;
    }

    /**
     * Return blade file within Response
     *
     * @param string $view
     * @param array  $data
     * @param array  $mergeData
     *
     * @return Response|void
     */
    public function blade($view, array $data = [], array $mergeData = [])
    {
        if (function_exists('app')) {
            $this->setContent(
                app('view')->make($view, $data, $mergeData)->render()
            );

            return $this;
        }

        return;
    }

    /**
     * @return Response|string
     */
    public function __toString()
    {
        if ($this->json) {
            $this->headers->set('Content-Type', 'application/json; charset=' . $this->getCharset());
        }

        return $this->send();
    }
}


<?php

namespace Nur\Http;

class Http
{
    /**
     * HTTP POST Request
     *
     * @param string $key
     * @param bool   $filter
     *
     * @return string|null
     */
    public function post($key = null, $filter = false)
    {
        if (is_null($key)) {
            return $_POST;
        }

        $value = (isset($_POST[$key]) ? $_POST[$key] : null);

        return $this->filter($value, $filter);
    }

    /**
     * HTTP GET Request
     *
     * @param string $key
     * @param bool   $filter
     *
     * @return string|null
     */
    public function get($key = null, $filter = false)
    {
        if (is_null($key)) {
            return $_GET;
        }

        $value = (isset($_GET[$key]) ? $_GET[$key] : null);

        return $this->filter($value, $filter);
    }

    /**
     * HTTP PUT Request
     *
     * @param string $key
     * @param bool   $filter
     *
     * @return string|null
     */
    public function put($key = null, $filter = true)
    {
        parse_str(file_get_contents("php://input"), $_PUT);

        if ($key == null) {
            return $_PUT;
        }

        return $this->filter($_PUT[$key], $filter);
    }

    /**
     * HTTP DELETE Request
     *
     * @param string $key
     * @param bool   $filter
     *
     * @return string|null
     */
    public function delete($key = null, $filter = true)
    {
        parse_str(file_get_contents("php://input"), $_DELETE);

        if ($key == null) {
            return $_DELETE;
        }

        return $this->filter($_DELETE[$key], $filter);
    }

    /**
     * HTTP REQUEST method. (Post or Get Request)
     *
     * @param string $key
     * @param bool   $filter
     *
     * @return string|null
     */
    public function request($key = null, $filter = false)
    {
        if (is_null($key)) {
            return $_REQUEST;
        }

        $value = (isset($_REQUEST[$key]) ? $_REQUEST[$key] : null);

        return $this->filter($value, $filter);
    }

    /**
     * HTTP FILES Request
     *
     * @param string $key
     * @param string $name
     *
     * @return mixed
     */
    public function files($key = null, $name = null)
    {
        if (is_null($key)) {
            return $_FILES;
        }

        if (isset($_FILES[$key])) {
            if (! is_null($name)) {
                return $_FILES[$key][$name];
            }

            return $_FILES[$key];
        }

        return false;
    }

    /**
     * HTTP SERVER Request
     *
     * @param string $key
     *
     * @return string|null
     */
    public function server($key = null)
    {
        if (is_null($key)) {
            return $_SERVER;
        }

        $key = strtoupper($key);
        return (isset($_SERVER[$key]) ? $_SERVER[$key] : null);
    }

    /**
     * Get current request method.
     *
     * @return string
     */
    public function method()
    {
        return $this->server('REQUEST_METHOD');
    }

    /**
     * Get Client IP Address.
     *
     * @return string
     */
    public function getClientIP()
    {
        $ip = null;
        $client = $this->server('HTTP_CLIENT_IP');
        $forward = $this->server('HTTP_X_FORWARDED_FOR');
        $remote = $this->server('REMOTE_ADDR');

        if (filter_var($client, FILTER_VALIDATE_IP)) {
            $ip = $client;
        } elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
            $ip = $forward;
        } else {
            $ip = $remote;
        }

        return $ip;
    }

    /**
     * Filter method for HTTP Values.
     *
     * @param string $data
     * @param bool   $filter
     *
     * @return string|null
     */
    public function filter($data = null, $filter = false)
    {
        if (is_null($data)) {
            return null;
        }

        if (is_array($data)) {
            return array_map(function ($value) use ($filter) {
                return $this->filter($value, $filter);
            }, $data);
        }

        return ($filter == true ? $this->xssClean($data) : trim($data));
    }

    /**
     * Clear XSS
     *
     * @param string $data
     *
     * @return string
     */
    public function xssClean($data)
    {
        // Fix &entity\n;
        $data = str_replace(['&', '<', '>'], ['&amp;', '&lt;', '&gt;'], $data);
        $data = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $data);
        $data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data);
        $data = html_entity_decode($data, ENT_COMPAT, 'UTF-8');
        // Remove any attribute starting with "on" or xmlns
        $data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data);
        // Remove javascript: and vbscript: protocols
        $data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu',
            '$1=$2nojavascript...', $data);
        $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu',
            '$1=$2novbscript...', $data);
        $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u',
            '$1=$2nomozbinding...', $data);
        // Only works in IE:
        $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i',
            '$1>', $data);
        $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i',
            '$1>', $data);
        $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu',
            '$1>', $data);
        // Remove namespaced elements (we do not need them)
        $data = preg_replace('#</*\w+:\w[^>]*+>#i', '', $data);

        do {
            // Remove really unwanted tags
            $old_data = $data;
            $data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i',
                '', $data);
        } while ($old_data !== $data);
        // we are done...
        return $data;
    }
}


<?php

namespace Nur\Providers;

use Nur\Kernel\ServiceProvider;

class Html extends ServiceProvider
{
    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = true;

    /**
     * Register the service provider.
     *
     * @return void
     * @throws
     */
    public function register()
    {
        $this->app->singleton('html', \Nur\Components\Builder\Html::class);
        $this->app->singleton('form', \Nur\Components\Builder\Form::class);
    }
}


<?php

namespace Nur\Console\Commands\Migrations;

use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Nur\Console\Commands\Migrations\AbstractCommand;

class CheckCommand extends AbstractCommand
{
    protected function configure()
    {
        parent::configure();

        $this->setName('check')
             ->setDescription('Check all migrations have been run, exit with non-zero if not')
             ->setHelp(<<<EOT
The <info>check</info> checks that all migrations have been run and exits with a
non-zero exit code if not, useful for build or deployment scripts.

<info>migration:check</info>

EOT
        );
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->bootstrap($input, $output);
        $versions = $this->getAdapter()->fetchAll();
        $down = [];
        foreach($this->getMigrations() as $migration) {
            if (!in_array($migration->getVersion(), $versions)) {
                $down[] = $migration;
            }
        }

        if (!empty($down)) {
            $rows = [];
            foreach($down as $migration) {
                $status = '<error> DOWN </error>';
                $rows[] = [
                    $status,
                    $migration->getVersion(),
                    $migration->getName(),
                    date('d M Y H:i:s', strtotime($migration->getVersion()))
                ];
            }

            $table = new Table($output);
            $table->setHeaders(array('Status', 'Migration ID', 'Migration Name', 'Created at'))
                ->setRows($rows)
            ;
            $table->render();
        }

        return 0;
    }
}


<?php
/**
 * EventAttributes
 *
 * PHP version 5
 *
 * @category Class
 * @package  ProcessMaker\PMIO
 * @author   http://github.com/swagger-api/swagger-codegen
 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
 * @link     https://github.com/swagger-api/swagger-codegen
 */

/**
 * ProcessMaker API
 *
 * This ProcessMaker I/O API provides access to a BPMN 2.0 compliant workflow engine API that is designed to be used as a microservice to support enterprise cloud applications. The current Alpha 1.0 version supports most of the descriptive classes of the BPMN 2.0 specification.
 *
 * OpenAPI spec version: 1.0.0
 * Contact: support@processmaker.io
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen
 * Do not edit the class manually.
 */

namespace ProcessMaker\PMIO\Model;

use \ArrayAccess;

/**
 * EventAttributes Class Doc Comment
 *
 * @category    Class */
/**
 * @package     ProcessMaker\PMIO
 * @author      http://github.com/swagger-api/swagger-codegen
 * @license     http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
 * @link        https://github.com/swagger-api/swagger-codegen
 */
class EventAttributes implements ArrayAccess
{
    /**
      * The original name of the model.
      * @var string
      */
    protected static $swaggerModelName = 'Event_attributes';

    /**
      * Array of property to type mappings. Used for (de)serialization
      * @var string[]
      */
    protected static $swaggerTypes = array(
        'name' => 'string',
        'description' => 'string',
        'process_id' => 'string',
        'message_id' => 'int',
        'type' => 'string',
        'definition' => 'string',
        'interrupting' => 'bool',
        'condition' => 'string',
        'time' => 'string',
        'duration' => 'string',
        'cycle' => 'string',
        'attached_to_task_id' => 'string',
        'ref_id' => 'string',
        'created_at' => 'string',
        'updated_at' => 'string'
    );

    public static function swaggerTypes()
    {
        return self::$swaggerTypes;
    }

    /**
     * Array of attributes where the key is the local name, and the value is the original name
     * @var string[]
     */
    protected static $attributeMap = array(
        'name' => 'name',
        'description' => 'description',
        'process_id' => 'process_id',
        'message_id' => 'message_id',
        'type' => 'type',
        'definition' => 'definition',
        'interrupting' => 'interrupting',
        'condition' => 'condition',
        'time' => 'time',
        'duration' => 'duration',
        'cycle' => 'cycle',
        'attached_to_task_id' => 'attached_to_task_id',
        'ref_id' => 'ref_id',
        'created_at' => 'created_at',
        'updated_at' => 'updated_at'
    );

    public static function attributeMap()
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     * @var string[]
     */
    protected static $setters = array(
        'name' => 'setName',
        'description' => 'setDescription',
        'process_id' => 'setProcessId',
        'message_id' => 'setMessageId',
        'type' => 'setType',
        'definition' => 'setDefinition',
        'interrupting' => 'setInterrupting',
        'condition' => 'setCondition',
        'time' => 'setTime',
        'duration' => 'setDuration',
        'cycle' => 'setCycle',
        'attached_to_task_id' => 'setAttachedToTaskId',
        'ref_id' => 'setRefId',
        'created_at' => 'setCreatedAt',
        'updated_at' => 'setUpdatedAt'
    );

    public static function setters()
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests)
     * @var string[]
     */
    protected static $getters = array(
        'name' => 'getName',
        'description' => 'getDescription',
        'process_id' => 'getProcessId',
        'message_id' => 'getMessageId',
        'type' => 'getType',
        'definition' => 'getDefinition',
        'interrupting' => 'getInterrupting',
        'condition' => 'getCondition',
        'time' => 'getTime',
        'duration' => 'getDuration',
        'cycle' => 'getCycle',
        'attached_to_task_id' => 'getAttachedToTaskId',
        'ref_id' => 'getRefId',
        'created_at' => 'getCreatedAt',
        'updated_at' => 'getUpdatedAt'
    );

    public static function getters()
    {
        return self::$getters;
    }

    const TYPE_START = 'START';
    const TYPE_END = 'END';
    const TYPE_INTERMEDIATE_CATCH = 'INTERMEDIATE_CATCH';
    const TYPE_INTERMEDIATE_THROW = 'INTERMEDIATE_THROW';
    const TYPE_BOUNDARY = 'BOUNDARY';
    const TYPE_IMPLICIT_THROW = 'IMPLICIT_THROW';
    const DEFINITION_NONE = 'NONE';
    const DEFINITION_CANCEL = 'CANCEL';
    const DEFINITION_COMPENSATION = 'COMPENSATION';
    const DEFINITION_ERROR = 'ERROR';
    const DEFINITION_ESCALATION = 'ESCALATION';
    const DEFINITION_MESSAGE = 'MESSAGE';
    const DEFINITION_LINK = 'LINK';
    const DEFINITION_SIGNAL = 'SIGNAL';
    const DEFINITION_TERMINATE = 'TERMINATE';
    const DEFINITION_TIMER = 'TIMER';

    /**
     * Gets allowable values of the enum
     * @return string[]
     */
    public function getTypeAllowableValues()
    {
        return [
            self::TYPE_START,
            self::TYPE_END,
            self::TYPE_INTERMEDIATE_CATCH,
            self::TYPE_INTERMEDIATE_THROW,
            self::TYPE_BOUNDARY,
            self::TYPE_IMPLICIT_THROW,
        ];
    }

    /**
     * Gets allowable values of the enum
     * @return string[]
     */
    public function getDefinitionAllowableValues()
    {
        return [
            self::DEFINITION_NONE,
            self::DEFINITION_CANCEL,
            self::DEFINITION_COMPENSATION,
            self::DEFINITION_ERROR,
            self::DEFINITION_ESCALATION,
            self::DEFINITION_MESSAGE,
            self::DEFINITION_LINK,
            self::DEFINITION_SIGNAL,
            self::DEFINITION_TERMINATE,
            self::DEFINITION_TIMER,
        ];
    }

    /**
     * Associative array for storing property values
     * @var mixed[]
     */
    protected $container = array();

    /**
     * Constructor
     * @param mixed[] $data Associated array of property value initalizing the model
     */
    public function __construct(array $data = null)
    {
        $this->container['name'] = isset($data['name']) ? $data['name'] : null;
        $this->container['description'] = isset($data['description']) ? $data['description'] : null;
        $this->container['process_id'] = isset($data['process_id']) ? $data['process_id'] : null;
        $this->container['message_id'] = isset($data['message_id']) ? $data['message_id'] : null;
        $this->container['type'] = isset($data['type']) ? $data['type'] : null;
        $this->container['definition'] = isset($data['definition']) ? $data['definition'] : null;
        $this->container['interrupting'] = isset($data['interrupting']) ? $data['interrupting'] : null;
        $this->container['condition'] = isset($data['condition']) ? $data['condition'] : null;
        $this->container['time'] = isset($data['time']) ? $data['time'] : null;
        $this->container['duration'] = isset($data['duration']) ? $data['duration'] : null;
        $this->container['cycle'] = isset($data['cycle']) ? $data['cycle'] : null;
        $this->container['attached_to_task_id'] = isset($data['attached_to_task_id']) ? $data['attached_to_task_id'] : null;
        $this->container['ref_id'] = isset($data['ref_id']) ? $data['ref_id'] : null;
        $this->container['created_at'] = isset($data['created_at']) ? $data['created_at'] : null;
        $this->container['updated_at'] = isset($data['updated_at']) ? $data['updated_at'] : null;
    }

    /**
     * show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties()
    {
        $invalid_properties = array();
        if ($this->container['name'] === null) {
            $invalid_properties[] = "'name' can't be null";
        }
        if ($this->container['process_id'] === null) {
            $invalid_properties[] = "'process_id' can't be null";
        }
        if ($this->container['type'] === null) {
            $invalid_properties[] = "'type' can't be null";
        }
        $allowed_values = array("START", "END", "INTERMEDIATE_CATCH", "INTERMEDIATE_THROW", "BOUNDARY", "IMPLICIT_THROW");
        if (!in_array($this->container['type'], $allowed_values)) {
            $invalid_properties[] = "invalid value for 'type', must be one of #{allowed_values}.";
        }

        if ($this->container['definition'] === null) {
            $invalid_properties[] = "'definition' can't be null";
        }
        $allowed_values = array("NONE", "CANCEL", "COMPENSATION", "ERROR", "ESCALATION", "MESSAGE", "LINK", "SIGNAL", "TERMINATE", "TIMER");
        if (!in_array($this->container['definition'], $allowed_values)) {
            $invalid_properties[] = "invalid value for 'definition', must be one of #{allowed_values}.";
        }

        if (!is_null($this->container['ref_id']) && (strlen($this->container['ref_id']) > 255)) {
            $invalid_properties[] = "invalid value for 'ref_id', the character length must be smaller than or equal to 255.";
        }

        return $invalid_properties;
    }

    /**
     * validate all the properties in the model
     * return true if all passed
     *
     * @return bool True if all properteis are valid
     */
    public function valid()
    {
        if ($this->container['name'] === null) {
            return false;
        }
        if ($this->container['process_id'] === null) {
            return false;
        }
        if ($this->container['type'] === null) {
            return false;
        }
        $allowed_values = array("START", "END", "INTERMEDIATE_CATCH", "INTERMEDIATE_THROW", "BOUNDARY", "IMPLICIT_THROW");
        if (!in_array($this->container['type'], $allowed_values)) {
            return false;
        }
        if ($this->container['definition'] === null) {
            return false;
        }
        $allowed_values = array("NONE", "CANCEL", "COMPENSATION", "ERROR", "ESCALATION", "MESSAGE", "LINK", "SIGNAL", "TERMINATE", "TIMER");
        if (!in_array($this->container['definition'], $allowed_values)) {
            return false;
        }
        if (strlen($this->container['ref_id']) > 255) {
            return false;
        }
        return true;
    }

    /**
     * Gets name
     * @return string
     */
    public function getName()
    {
        return $this->container['name'];
    }

    /**
     * Sets name
     * @param string $name
     * @return $this
     */
    public function setName($name)
    {
        $this->container['name'] = $name;

        return $this;
    }

    /**
     * Gets description
     * @return string
     */
    public function getDescription()
    {
        return $this->container['description'];
    }

    /**
     * Sets description
     * @param string $description
     * @return $this
     */
    public function setDescription($description)
    {
        $this->container['description'] = $description;

        return $this;
    }

    /**
     * Gets process_id
     * @return string
     */
    public function getProcessId()
    {
        return $this->container['process_id'];
    }

    /**
     * Sets process_id
     * @param string $process_id
     * @return $this
     */
    public function setProcessId($process_id)
    {
        $this->container['process_id'] = $process_id;

        return $this;
    }

    /**
     * Gets message_id
     * @return int
     */
    public function getMessageId()
    {
        return $this->container['message_id'];
    }

    /**
     * Sets message_id
     * @param int $message_id
     * @return $this
     */
    public function setMessageId($message_id)
    {
        $this->container['message_id'] = $message_id;

        return $this;
    }

    /**
     * Gets type
     * @return string
     */
    public function getType()
    {
        return $this->container['type'];
    }

    /**
     * Sets type
     * @param string $type
     * @return $this
     */
    public function setType($type)
    {
        $allowed_values = array('START', 'END', 'INTERMEDIATE_CATCH', 'INTERMEDIATE_THROW', 'BOUNDARY', 'IMPLICIT_THROW');
        if (!in_array($type, $allowed_values)) {
            throw new \InvalidArgumentException("Invalid value for 'type', must be one of 'START', 'END', 'INTERMEDIATE_CATCH', 'INTERMEDIATE_THROW', 'BOUNDARY', 'IMPLICIT_THROW'");
        }
        $this->container['type'] = $type;

        return $this;
    }

    /**
     * Gets definition
     * @return string
     */
    public function getDefinition()
    {
        return $this->container['definition'];
    }

    /**
     * Sets definition
     * @param string $definition
     * @return $this
     */
    public function setDefinition($definition)
    {
        $allowed_values = array('NONE', 'CANCEL', 'COMPENSATION', 'ERROR', 'ESCALATION', 'MESSAGE', 'LINK', 'SIGNAL', 'TERMINATE', 'TIMER');
        if (!in_array($definition, $allowed_values)) {
            throw new \InvalidArgumentException("Invalid value for 'definition', must be one of 'NONE', 'CANCEL', 'COMPENSATION', 'ERROR', 'ESCALATION', 'MESSAGE', 'LINK', 'SIGNAL', 'TERMINATE', 'TIMER'");
        }
        $this->container['definition'] = $definition;

        return $this;
    }

    /**
     * Gets interrupting
     * @return bool
     */
    public function getInterrupting()
    {
        return $this->container['interrupting'];
    }

    /**
     * Sets interrupting
     * @param bool $interrupting
     * @return $this
     */
    public function setInterrupting($interrupting)
    {
        $this->container['interrupting'] = $interrupting;

        return $this;
    }

    /**
     * Gets condition
     * @return string
     */
    public function getCondition()
    {
        return $this->container['condition'];
    }

    /**
     * Sets condition
     * @param string $condition
     * @return $this
     */
    public function setCondition($condition)
    {
        $this->container['condition'] = $condition;

        return $this;
    }

    /**
     * Gets time
     * @return string
     */
    public function getTime()
    {
        return $this->container['time'];
    }

    /**
     * Sets time
     * @param string $time
     * @return $this
     */
    public function setTime($time)
    {
        $this->container['time'] = $time;

        return $this;
    }

    /**
     * Gets duration
     * @return string
     */
    public function getDuration()
    {
        return $this->container['duration'];
    }

    /**
     * Sets duration
     * @param string $duration
     * @return $this
     */
    public function setDuration($duration)
    {
        $this->container['duration'] = $duration;

        return $this;
    }

    /**
     * Gets cycle
     * @return string
     */
    public function getCycle()
    {
        return $this->container['cycle'];
    }

    /**
     * Sets cycle
     * @param string $cycle
     * @return $this
     */
    public function setCycle($cycle)
    {
        $this->container['cycle'] = $cycle;

        return $this;
    }

    /**
     * Gets attached_to_task_id
     * @return string
     */
    public function getAttachedToTaskId()
    {
        return $this->container['attached_to_task_id'];
    }

    /**
     * Sets attached_to_task_id
     * @param string $attached_to_task_id
     * @return $this
     */
    public function setAttachedToTaskId($attached_to_task_id)
    {
        $this->container['attached_to_task_id'] = $attached_to_task_id;

        return $this;
    }

    /**
     * Gets ref_id
     * @return string
     */
    public function getRefId()
    {
        return $this->container['ref_id'];
    }

    /**
     * Sets ref_id
     * @param string $ref_id Set as XML object ID if imported from BPMN file or can be optionally set when object added via API. Used to optionally refer object by ref_id instead of using its UUID.
     * @return $this
     */
    public function setRefId($ref_id)
    {
        if (strlen($ref_id) > 255) {
            throw new \InvalidArgumentException('invalid length for $ref_id when calling EventAttributes., must be smaller than or equal to 255.');
        }
        $this->container['ref_id'] = $ref_id;

        return $this;
    }

    /**
     * Gets created_at
     * @return string
     */
    public function getCreatedAt()
    {
        return $this->container['created_at'];
    }

    /**
     * Sets created_at
     * @param string $created_at
     * @return $this
     */
    public function setCreatedAt($created_at)
    {
        $this->container['created_at'] = $created_at;

        return $this;
    }

    /**
     * Gets updated_at
     * @return string
     */
    public function getUpdatedAt()
    {
        return $this->container['updated_at'];
    }

    /**
     * Sets updated_at
     * @param string $updated_at
     * @return $this
     */
    public function setUpdatedAt($updated_at)
    {
        $this->container['updated_at'] = $updated_at;

        return $this;
    }
    /**
     * Returns true if offset exists. False otherwise.
     * @param  integer $offset Offset
     * @return boolean
     */
    public function offsetExists($offset)
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     * @param  integer $offset Offset
     * @return mixed
     */
    public function offsetGet($offset)
    {
        return isset($this->container[$offset]) ? $this->container[$offset] : null;
    }

    /**
     * Sets value based on offset.
     * @param  integer $offset Offset
     * @param  mixed   $value  Value to be set
     * @return void
     */
    public function offsetSet($offset, $value)
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     * @param  integer $offset Offset
     * @return void
     */
    public function offsetUnset($offset)
    {
        unset($this->container[$offset]);
    }

    /**
     * Gets the string presentation of the object
     * @return string
     */
    public function __toString()
    {
        if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print
            return json_encode(\ProcessMaker\PMIO\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT);
        }

        return json_encode(\ProcessMaker\PMIO\ObjectSerializer::sanitizeForSerialization($this));
    }
}


<?php

namespace Nur\Components\Validation;

class Validation
{
    /**
     * Validation errors
     *
     * @var array
     */
    protected $errors = [];

    /**
     * Label for fields
     *
     * @var array
     */
    protected $labels = [];

    /**
     * Validation rules
     *
     * @var array
     */
    protected $rules = [];

    /**
     * Data to validate
     *
     * @var array
     */
    protected $data = [];

    /**
     * Fields validation error messages
     *
     * @var array
     */
    protected $texts = [];

    /**
     * Default validation error message
     *
     * @var string
     */
    protected $msg = '%s is not valid.';

    /**
     * Define Validation Rules
     *
     * @param array $rules
     *
     * @return void
     */
    public function rules(Array $rules)
    {
        foreach ($rules as $key => $value) {
            $this->rule(
                $key, $value['label'],
                $value['rules'],
                isset($value['text']) && ! empty($value['text']) ? $value['text'] : []
            );
        }
    }

    /**
     * Define One Validation Rule
     *
     * @param string $field
     * @param string $label
     * @param string $rules
     * @param array  $text
     *
     * @return void
     */
    public function rule($field, $label, $rules, array $text = [])
    {
        $this->labels[$field] = $label;
        $this->rules[$field] = $rules;
        $this->texts[$field] = (! empty($text) ? $text : null);
    }

    /**
     * Validate
     *
     * @param array $data
     *
     * @return boolean
     */
    public function isValid(array $data = [])
    {
        if (empty($data)) {
            $data = http()->method() == 'GET' ? http()->get() : http()->post();
        }
        $this->data = $data;

        foreach ($this->rules as $key => $value) {
            $rules = explode('|', $value);
            foreach ($rules as $rule) {
                if (strpos($rule, ',')) {
                    $group = explode(',', $rule);
                    $filter = $group[0];
                    $params = $group[1];
                    $this->errorMessage($filter, $key, $params);
                } else {
                    $this->errorMessage($rule, $key);
                }
            }
        }

        $this->errors = array_values(array_unique($this->errors));
        if (count($this->errors) > 0) {
            return false;
        }

        return true;
    }

    /**
     * Sanitizing Data
     *
     * @param string $data
     *
     * @return string
     */
    public function sanitize($data)
    {
        if (! is_array($data)) {
            return filter_var(trim($data), FILTER_SANITIZE_STRING);
        }

        foreach ($data as $key => $value) {
            $data[$key] = filter_var($value, FILTER_SANITIZE_STRING);
        }
        return $data;
    }

    /**
     * Return errors
     *
     * @return array
     */
    public function errors()
    {
        return $this->errors;
    }

    /**
     * Field validation error messages
     *
     * @param string $filter
     * @param string $field
     * @param string $params
     *
     * @return void
     */
    protected function errorMessage($filter, $field, $params = null)
    {
        $text = (isset($this->texts[$field][$filter]) && ! is_null($this->texts[$field][$filter])
            ? $this->texts[$field][$filter] : $this->msg);
        $text = str_replace([':label:', ':value:'], '%s', $text);

        if (! isset($this->data[$field])) {
            $this->errors[] = sprintf($text, $this->labels[$field], $params);
        } elseif (! is_null($params)) {
            if ($filter == 'matches') {
                if ($this->matches($this->data[$field], $this->data[$params]) === false) {
                    $this->errors[] = sprintf($text, $this->labels[$field], $params);
                }
            } else {
                if ($this->$filter($this->data[$field], $params) === false) {
                    $this->errors[] = sprintf($text, $this->labels[$field], $params);
                }
            }
        } else {
            if ($this->$filter($this->data[$field]) === false) {
                $this->errors[] = sprintf($text, $this->labels[$field], $params);
            }
        }
    }

    /**
     * Required Field Control
     *
     * @param string $data
     *
     * @return boolean
     */
    protected function required($data)
    {
        return (! empty($data) && ! is_null($data) && $data !== '');
    }

    /**
     * Numeric Field Control
     *
     * @param int $data
     *
     * @return boolean
     */
    protected function numeric($data)
    {
        return (is_numeric($data));
    }

    /**
     * Email Validation
     *
     * @param string $email
     *
     * @return boolean
     */
    protected function email($email)
    {
        return (filter_var($email, FILTER_VALIDATE_EMAIL));
    }

    /**
     * Minimum Character Check
     *
     * @param string $data
     * @param int    $length
     *
     * @return boolean
     */
    protected function min_len($data, $length)
    {
        return (strlen($data) >= $length);
    }

    /**
     * Maximum Character Check
     *
     * @param string $data
     * @param int    $length
     *
     * @return boolean
     */
    protected function max_len($data, $length)
    {
        return (strlen($data) <= $length);
    }

    /**
     * Exact Length Check
     *
     * @param string $data
     * @param int    $length
     *
     * @return boolean
     */
    protected function exact_len($data, $length)
    {
        return (strlen($data) == $length);
    }

    /**
     * Alpha Character Validation
     *
     * @param string $data
     *
     * @return boolean
     */
    protected function alpha($data)
    {
        return (preg_match('/^[a-zA-ZÇçĞğİıÖöŞşÜü]+$/i', $data)
            ? true : ctype_alpha($data));
    }

    /**
     * Alphanumeric Character Validation
     *
     * @param string $data
     *
     * @return boolean
     */
    protected function alpha_num($data)
    {
        return (preg_match('/^[0-9a-zA-ZÇçĞğİıÖöŞşÜü]+$/i', $data)
            ? true : ctype_alnum($data));
    }

    /**
     * Alpha-dash Character Validation
     *
     * @param string $data
     *
     * @return boolean
     */
    protected function alpha_dash($data)
    {
        return ! (! preg_match("/^([A-Za-z0-9_-])+$/i", $data));
    }

    /**
     * Alpha-space Character Validation
     *
     * @param string $data
     *
     * @return boolean
     */
    protected function alpha_space($data)
    {
        return ! (! preg_match("/^([A-Za-z0-9- ])+$/i", $data));
    }

    /**
     * Integer Validation
     *
     * @param int $data
     *
     * @return boolean
     */
    protected function integer($data)
    {
        return ! (! preg_match("/^([0-9])+$/i", $data));
    }

    /**
     * Boolean Validation
     *
     * @param string $data
     *
     * @return boolean
     */
    protected function boolean($data)
    {
        return ($data === true || $data === false);
    }

    /**
     * Float Validation
     *
     * @param string $data
     *
     * @return boolean
     */
    protected function float($data)
    {
        return (! preg_match("/^([0-9\.])+$/i", $data)) ? false : true;
    }

    /**
     * URL Validation
     *
     * @param string $url
     *
     * @return boolean
     */
    protected function valid_url($url)
    {
        return (filter_var($url, FILTER_VALIDATE_URL));
    }

    /**
     * IP Validation
     *
     * @param string $ip
     *
     * @return boolean
     */
    protected function valid_ip($ip)
    {
        return (filter_var($ip, FILTER_VALIDATE_IP));
    }

    /**
     * IPv4 Validation
     *
     * @param string $ip
     *
     * @return boolean
     */
    protected function valid_ipv4($ip)
    {
        return (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4));
    }

    /**
     * IPv6 Validation
     *
     * @param string $ip
     *
     * @return boolean
     */
    protected function valid_ipv6($ip)
    {
        return (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
    }

    /**
     * Credit Card Validation
     *
     * @param string $data
     *
     * @return boolean
     */
    protected function valid_cc($data)
    {
        $number = preg_replace('/\D/', '', $data);
        if (function_exists('mb_strlen')) {
            $number_length = mb_strlen($number);
        } else {
            $number_length = strlen($number);
        }

        $parity = $number_length % 2;
        $total = 0;
        for ($i = 0; $i < $number_length; $i++) {
            $digit = $number[$i];

            if ($i % 2 == $parity) {
                $digit *= 2;

                if ($digit > 9) {
                    $digit -= 9;
                }
            }

            $total += $digit;
        }

        return ($total % 10 == 0) ? true : false;
    }

    /**
     * Field must contain something
     *
     * @param string $data
     * @param string $part
     *
     * @return boolean
     */
    protected function contains($data, $part)
    {
        return (strpos($data, $part) !== false);
    }

    /**
     * Minimum Value Validation
     *
     * @param int $data
     * @param int $min
     *
     * @return boolean
     */
    protected function min_numeric($data, $min)
    {
        return (is_numeric($data) && is_numeric($min) && $data >= $min);
    }

    /**
     * Maximum Value Validation
     *
     * @param int $data
     * @param int $max
     *
     * @return boolean
     */
    protected function max_numeric($data, $max)
    {
        return (is_numeric($data) && is_numeric($max) && $data <= $max);
    }

    /**
     * Matched Fields Validation
     *
     * @param string $data
     * @param string $field
     *
     * @return bool
     */
    protected function matches($data, $field)
    {
        return ($data == $field);
    }
}


<?php

namespace Nur\Console\Commands\Migrations;

use Phpmig\Adapter\AdapterInterface;
use Phpmig\Migration\Migration;
use Phpmig\Migration\Migrator;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * This file is part of phpmig
 *
 * Copyright (c) 2011 Dave Marshall <dave.marshall@atstsolutuions.co.uk>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Abstract command, contains bootstrapping info
 *
 * @author      Dave Marshall <david.marshall@atstsolutions.co.uk>
 */
abstract class AbstractCommand extends Command
{
    /**
     * @var \ArrayAccess
     */
    protected $container = null;

    /**
     * @var AdapterInterface
     */
    protected $adapter = null;

    /**
     * @var string
     */
    protected $bootstrap = null;

    /**
     * @var array
     */
    protected $migrations = array();

    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this->addOption('--set', '-s', InputOption::VALUE_REQUIRED, 'The phpmig.sets key');
        $this->addOption('--bootstrap', '-b', InputOption::VALUE_REQUIRED, 'The bootstrap file to load');
    }

    /**
     * Bootstrap phpmig
     *
     * @return void
     */
    protected function bootstrap(InputInterface $input, OutputInterface $output)
    {
        $this->setBootstrap($this->findBootstrapFile($input->getOption('bootstrap')));

        $container = $this->bootstrapContainer();
        $this->setContainer($container);
        $this->setAdapter($this->bootstrapAdapter($input));

        $this->setMigrations($this->bootstrapMigrations($input, $output));

        $container['phpmig.migrator'] = $this->bootstrapMigrator($output);
    }

    /**
     * @param string $filename
     * @return array|string
     */
    protected function findBootstrapFile($filename)
    {
        if ($filename === null) {
            $filename = base_path('/vendor/izniburak/nur-core/src/Database/Migration/MigrationRegister.php');
        }

        $locator = new FileLocator(array(
            config_path(), base_path()
        ));

        return $locator->locate($filename);
    }

    /**
     * @return \ArrayAccess The container
     * @throws \RuntimeException
     */
    protected function bootstrapContainer()
    {
        $bootstrapFile = $this->getBootstrap();

        $func = function () use ($bootstrapFile) {
            return require $bootstrapFile;
        };

        $container = $func();

        if (!($container instanceof \ArrayAccess)) {
            throw new \RuntimeException($bootstrapFile . " must return object of type \ArrayAccess");
        }

        return $container;
    }

    /**
     * @param InputInterface  $input
     * @return AdapterInterface
     * @throws \RuntimeException
     */
    protected function bootstrapAdapter(InputInterface $input)
    {
        $container = $this->getContainer();

        $validAdapter = isset($container['phpmig.adapter']);
        $validSets = !isset($container['phpmig.sets']) || is_array($container['phpmig.sets']);

        if (!$validAdapter && !$validSets) {
            throw new \RuntimeException(
                $this->getBootstrap()
                . 'must return container with phpmig.adapter or phpmig.sets'
            );
        }

        if (isset($container['phpmig.sets'])) {
            $set = $input->getOption('set');
            if (!isset($container['phpmig.sets'][$set]['adapter'])) {
                throw new \RuntimeException(
                    $set . ' is undefined keys or adapter at phpmig.sets'
                );
            }
            $adapter = $container['phpmig.sets'][$set]['adapter'];
        }
        if (isset($container['phpmig.adapter'])) {
            $adapter = $container['phpmig.adapter'];
        }

        if (!($adapter instanceof AdapterInterface)) {
            throw new \RuntimeException("phpmig.adapter or phpmig.sets must be an instance of \\Phpmig\\Adapter\\AdapterInterface");
        }

        if (!$adapter->hasSchema()) {
            $adapter->createSchema();
        }

        return $adapter;
    }

    /**
     * @param InputInterface  $input
     * @param OutputInterface $output
     * @throws \RuntimeException
     * @throws \InvalidArgumentException
     */
    protected function bootstrapMigrations(InputInterface $input, OutputInterface $output)
    {
        $container = $this->getContainer();
        $set = $input->getOption('set');

        if (!isset($container['phpmig.migrations']) && !isset($container['phpmig.migrations_path']) && !isset($container['phpmig.sets'][$set]['migrations_path'])) {
            throw new \RuntimeException($this->getBootstrap() . ' must return container with array at phpmig.migrations or migrations default path at phpmig.migrations_path or migrations default path at phpmig.sets');
        }

        $migrations = array();
        if (isset($container['phpmig.migrations'])) {
            if (!is_array($container['phpmig.migrations'])) {
                throw new \RuntimeException($this->getBootstrap() . ' phpmig.migrations must be an array.');
            }

            $migrations = $container['phpmig.migrations'];
        }
        if (isset($container['phpmig.migrations_path'])) {
            if (!is_dir($container['phpmig.migrations_path'])) {
                throw new \RuntimeException($this->getBootstrap() . ' phpmig.migrations_path must be a directory.');
            }

            $migrationsPath = realpath($container['phpmig.migrations_path']);
            $migrations = array_merge($migrations, glob($migrationsPath . DIRECTORY_SEPARATOR . '*.php'));
        }
        if (isset($container['phpmig.sets']) && isset($container['phpmig.sets'][$set]['migrations_path'])) {
            if (!is_dir($container['phpmig.sets'][$set]['migrations_path'])) {
                throw new \RuntimeException($this->getBootstrap() . " ['phpmig.sets']['" . $set . "']['migrations_path'] must be a directory.");
            }

            $migrationsPath = realpath($container['phpmig.sets'][$set]['migrations_path']);
            $migrations = array_merge($migrations, glob($migrationsPath . DIRECTORY_SEPARATOR . '*.php'));
        }
        $migrations = array_unique($migrations);

        $versions = array();
        $names = array();
        foreach ($migrations as $path) {
            if (!preg_match('/^[0-9]+/', basename($path), $matches)) {
                throw new \InvalidArgumentException(sprintf('The file "%s" does not have a valid migration filename', $path));
            }

            $version = $matches[0];
            if (isset($versions[$version])) {
                throw new \InvalidArgumentException(sprintf('Duplicate migration, "%s" has the same version as "%s"', $path, $versions[$version]->getName()));
            }

            $migrationName = preg_replace('/^[0-9]+_/', '', basename($path));
            if (false !== strpos($migrationName, '.')) {
                $migrationName = substr($migrationName, 0, strpos($migrationName, '.'));
            }
            $class = $this->migrationToClassName($migrationName);

            if ($this instanceof GenerateCommand
                && $class == $this->migrationToClassName($input->getArgument('name'))) {
                throw new \InvalidArgumentException(sprintf(
                    'Migration Class "%s" already exists',
                    $class
                ));
            }

            if (isset($names[$class])) {
                throw new \InvalidArgumentException(sprintf(
                    'Migration "%s" has the same name as "%s"',
                    $path,
                    $names[$class]
                ));
            }
            $names[$class] = $path;

            require_once $path;
            if (!class_exists($class)) {
                throw new \InvalidArgumentException(sprintf(
                    'Could not find class "%s" in file "%s"',
                    $class,
                    $path
                ));
            }

            $migration = new $class($version);

            if (!($migration instanceof Migration)) {
                throw new \InvalidArgumentException(sprintf(
                    'The class "%s" in file "%s" must extend \Phpmig\Migration\Migration',
                    $class,
                    $path
                ));
            }

            $migration->setOutput($output); // inject output

            $versions[$version] = $migration;
        }

        if (isset($container['phpmig.sets']) && isset($container['phpmig.sets'][$set]['connection'])) {
            $container['phpmig.connection'] = $container['phpmig.sets'][$set]['connection'];
        }

        ksort($versions);

        return $versions;
    }

    /**
     * @param OutputInterface $output
     * @return mixed
     */
    protected function bootstrapMigrator(OutputInterface $output)
    {
        return new Migrator($this->getAdapter(), $this->getContainer(), $output);
    }

    /**
     * Set bootstrap
     *
     * @var string
     * @return AbstractCommand
     */
    public function setBootstrap($bootstrap)
    {
        $this->bootstrap = $bootstrap;
        return $this;
    }

    /**
     * Get bootstrap
     *
     * @return string
     */
    public function getBootstrap()
    {
        return $this->bootstrap;
    }

    /**
     * Set migrations
     *
     * @param array $migrations
     * @return AbstractCommand
     */
    public function setMigrations(array $migrations)
    {
        $this->migrations = $migrations;
        return $this;
    }

    /**
     * Get migrations
     *
     * @return array
     */
    public function getMigrations()
    {
        return $this->migrations;
    }

    /**
     * Set container
     *
     * @var \ArrayAccess
     * @return AbstractCommand
     */
    public function setContainer(\ArrayAccess $container)
    {
        $this->container = $container;
        return $this;
    }

    /**
     * Get container
     *
     * @return \ArrayAccess
     */
    public function getContainer()
    {
        return $this->container;
    }

    /**
     * Set adapter
     *
     * @param AdapterInterface $adapter
     * @return AbstractCommand
     */
    public function setAdapter(AdapterInterface $adapter)
    {
        $this->adapter = $adapter;
        return $this;
    }

    /**
     * Get Adapter
     *
     * @return AdapterInterface
     */
    public function getAdapter()
    {
        return $this->adapter;
    }

    /**
     * transform create_table_user to CreateTableUser
     * @param $migrationName
     * @return string
     */
    protected function migrationToClassName( $migrationName )
    {
        $class = str_replace('_', ' ', $migrationName);
        $class = ucwords($class);
        $class = str_replace(' ', '', $class);

        if (!$this->isValidClassName($class)) {
            throw new \InvalidArgumentException(sprintf(
                'Migration class "%s" is invalid',
                $class
            ));
        }

        return $class;
    }

    /**
     * @param $className
     * @return bool
     * @see http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.class
     */
    private function isValidClassName($className)
    {
        return preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $className) === 1;
    }
}