<?php

namespace Nur\Kernel;

abstract class ServiceProvider
{
    /**
     * The application instance.
     *
     * @var \Nur\Container\Container
     */
    protected $app;

    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = false;

    /**
     * The paths that should be published.
     *
     * @var array
     */

    public static $publishes = [];
    /**
     * The paths that should be published by group.
     *
     * @var array
     */
    public static $publishGroups = [];

    /**
     * Create a new service provider instance.
     *
     * @param $app
     *
     * @return void
     */
    public function __construct($app)
    {
        $this->app = $app;
    }

    /**
     * Register paths to be published by the publish command.
     *
     * @param  array  $paths
     * @param  string  $group
     * @return void
     */
    protected function publishes(array $paths, $group = null)
    {
        $this->ensurePublishArrayInitialized($class = static::class);
        static::$publishes[$class] = array_merge(static::$publishes[$class], $paths);
        if ($group) {
            $this->addPublishGroup($group, $paths);
        }
    }

    /**
     * Ensure the publish array for the service provider is initialized.
     *
     * @param  string  $class
     * @return void
     */
    protected function ensurePublishArrayInitialized($class)
    {
        if (! array_key_exists($class, static::$publishes)) {
            static::$publishes[$class] = [];
        }
    }

    /**
     * Add a publish group / tag to the service provider.
     *
     * @param  string  $group
     * @param  array  $paths
     * @return void
     */
    protected function addPublishGroup($group, $paths)
    {
        if (! array_key_exists($group, static::$publishGroups)) {
            static::$publishGroups[$group] = [];
        }
        static::$publishGroups[$group] = array_merge(
            static::$publishGroups[$group], $paths
        );
    }

    /**
     * Get the paths to publish.
     *
     * @param  string  $provider
     * @param  string  $group
     * @return array
     */
    public static function pathsToPublish($provider = null, $group = null)
    {
        if (! is_null($paths = static::pathsForProviderOrGroup($provider, $group))) {
            return $paths;
        }
        return collect(static::$publishes)->reduce(function ($paths, $p) {
            return array_merge($paths, $p);
        }, []);
    }

    /**
     * Get the paths for the provider or group (or both).
     *
     * @param  string|null  $provider
     * @param  string|null  $group
     * @return array
     */
    protected static function pathsForProviderOrGroup($provider, $group)
    {
        if ($provider && $group) {
            return static::pathsForProviderAndGroup($provider, $group);
        } elseif ($group && array_key_exists($group, static::$publishGroups)) {
            return static::$publishGroups[$group];
        } elseif ($provider && array_key_exists($provider, static::$publishes)) {
            return static::$publishes[$provider];
        } elseif ($group || $provider) {
            return [];
        }
    }

    /**
     * Get the paths for the provider and group.
     *
     * @param  string  $provider
     * @param  string  $group
     * @return array
     */

    protected static function pathsForProviderAndGroup($provider, $group)
    {
        if (! empty(static::$publishes[$provider]) && ! empty(static::$publishGroups[$group])) {
            return array_intersect_key(static::$publishes[$provider], static::$publishGroups[$group]);
        }
        return [];
    }

    /**
     * Get the service providers available for publishing.
     *
     * @return array
     */
    public static function publishableProviders()
    {
        return array_keys(static::$publishes);
    }

    /**
     * Get the groups available for publishing.
     *
     * @return array
     */
    public static function publishableGroups()
    {
        return array_keys(static::$publishGroups);
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return [];
    }

    /**
     * Get the events that trigger this service provider to register.
     *
     * @return array
     */
    public function when()
    {
        return [];
    }

    /**
     * Determine if the provider is deferred.
     *
     * @return bool
     */
    public function isDeferred()
    {
        return $this->defer;
    }
}


<?php

namespace Nur\Log;

use Nur\Exception\ExceptionHandler;

class Log
{
    /**
     * Log file time format
     *
     * @var string
     */
    protected $timeFormat = 'Y-m-d H:i:s';

    /**
     * Save log as emergency
     *
     * @param mixed $message
     *
     * @return void
     */
    public function emergency($message)
    {
        $this->log('emergency', $message);
    }

    /**
     * Save log as alert
     *
     * @param mixed $message
     *
     * @return void
     */
    public function alert($message)
    {
        $this->log('alert', $message);
    }

    /**
     * Save log as critical
     *
     * @param mixed $message
     *
     * @return void
     */
    public function critical($message)
    {
        $this->log('critical', $message);
    }

    /**
     * Save log as error
     *
     * @param mixed $message
     *
     * @return void
     */
    public function error($message)
    {
        $this->log('error', $message);
    }

    /**
     * Save log as warning
     *
     * @param mixed $message
     *
     * @return void
     */
    public function warning($message)
    {
        $this->log('warning', $message);
    }

    /**
     * Save log as notice
     *
     * @param mixed $message
     *
     * @return void
     */
    public function notice($message)
    {
        $this->log('notice', $message);
    }

    /**
     * Save log as info
     *
     * @param mixed $message
     *
     * @return void
     */
    public function info($message)
    {
        $this->log('info', $message);
    }

    /**
     * Save log as debug
     *
     * @param mixed $message
     *
     * @return void
     */
    public function debug($message)
    {
        $this->log('debug', $message);
    }

    /**
     * Create log text to file
     *
     * @param string $level
     * @param mixed  $message
     *
     * @return void
     * @throws
     */
    protected function log($level, $message)
    {
        if (is_array($message) || is_object($message)) {
            // $message = json_encode($message);
            $message = print_r($message, true);
        }

        $text = '[' . date($this->timeFormat,
                time()) . '] - [' . strtoupper($level) . '] - [' . http()->getClientIP() . '] --> ' . $message;
        $this->save($text);
    }

    /**
     * Save Log
     *
     * @param string $text
     *
     * @return void
     * @throws
     */
    protected function save($text)
    {
        $fileName = 'log_' . date('Y-m-d') . '.log';
        $file = fopen(storage_path('log' . DIRECTORY_SEPARATOR . $fileName), 'a');

        if (fwrite($file, $text . "\n") === false) {
            throw new ExceptionHandler(
                'Oppss! Log file not created.',
                'Can you check chmod settings to save log file in log directory, please?'
            );
        }

        fclose($file);
    }
}


<?php

/** Adapted from \Illuminate\Http\Request class. */

namespace Nur\Http;

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use SplFileInfo;
use stdClass;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;

class Request extends SymfonyRequest
{
    use Macroable;

    /**
     * The decoded JSON content for the request.
     *
     * @var \Symfony\Component\HttpFoundation\ParameterBag|null
     */
    protected $json;

    /**
     * Class constructor.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER);
    }

    /**
     * Retrieve a server variable from the request.
     *
     * @param  string            $key
     * @param  string|array|null $default
     *
     * @return string|array
     */
    public function server($key = null, $default = null)
    {
        return $this->retrieveItem('server', $key, $default);
    }

    /**
     * Determine if a header is set on the request.
     *
     * @param  string $key
     *
     * @return bool
     */
    public function hasHeader($key)
    {
        return ! is_null($this->header($key));
    }

    /**
     * Retrieve a header from the request.
     *
     * @param  string            $key
     * @param  string|array|null $default
     *
     * @return string|array
     */
    public function header($key = null, $default = null)
    {
        return $this->retrieveItem('headers', $key, $default);
    }

    /**
     * Get the bearer token from the request headers.
     *
     * @return string|null
     */
    public function bearerToken()
    {
        $header = $this->header('Authorization', '');
        if (Str::startsWith($header, 'Bearer ')) {
            return Str::substr($header, 7);
        }
    }

    /**
     * Determine if the request contains a given input item key.
     *
     * @param  string|array $key
     *
     * @return bool
     */
    public function exists($key)
    {
        return $this->has($key);
    }

    /**
     * Determine if the request contains a given input item key.
     *
     * @param  string|array $key
     *
     * @return bool
     */
    public function has($key)
    {
        $keys = is_array($key) ? $key : func_get_args();
        $input = $this->all();
        foreach ($keys as $value) {
            if (! Arr::has($input, $value)) {
                return false;
            }
        }
        return true;
    }

    /**
     * Get all of the input and files for the request.
     *
     * @param  array|mixed $keys
     *
     * @return array
     */
    public function all($keys = null)
    {
        $input = array_replace_recursive($this->input(), $this->allFiles());
        if (! $keys) {
            return $input;
        }
        $results = [];
        foreach (is_array($keys) ? $keys : func_get_args() as $key) {
            Arr::set($results, $key, Arr::get($input, $key));
        }
        return $results;
    }

    /**
     * Retrieve an input item from the request.
     *
     * @param  string|null       $key
     * @param  string|array|null $default
     *
     * @return string|array|null
     */
    public function input($key = null, $default = null)
    {
        return data_get(
            $this->getInputSource()->all() + $this->query->all(), $key, $default
        );
    }

    /**
     * Determine if the request is sending JSON.
     *
     * @return bool
     */
    public function isJson()
    {
        return Str::contains($this->header('CONTENT_TYPE'), ['/json', '+json']);
    }

    /**
     * Get the JSON payload for the request.
     *
     * @param  string $key
     * @param  mixed  $default
     *
     * @return \Symfony\Component\HttpFoundation\ParameterBag|mixed
     */
    public function json($key = null, $default = null)
    {
        if (! isset($this->json)) {
            $this->json = new ParameterBag((array)json_decode($this->getContent(), true));
        }
        if (is_null($key)) {
            return $this->json;
        }
        return data_get($this->json->all(), $key, $default);
    }

    /**
     * Get an array of all of the files on the request.
     *
     * @return array
     */
    public function allFiles()
    {
        return $this->files->all();
    }

    /**
     * Determine if the request contains any of the given inputs.
     *
     * @param  string|array $keys
     *
     * @return bool
     */
    public function hasAny($keys)
    {
        $keys = is_array($keys) ? $keys : func_get_args();
        $input = $this->all();
        foreach ($keys as $key) {
            if (Arr::has($input, $key)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Determine if the request contains a non-empty value for any of the given inputs.
     *
     * @param  string|array $keys
     *
     * @return bool
     */
    public function anyFilled($keys)
    {
        $keys = is_array($keys) ? $keys : func_get_args();
        foreach ($keys as $key) {
            if ($this->filled($key)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Determine if the request contains a non-empty value for an input item.
     *
     * @param  string|array $key
     *
     * @return bool
     */
    public function filled($key)
    {
        $keys = is_array($key) ? $key : func_get_args();
        foreach ($keys as $value) {
            if ($this->isEmptyString($value)) {
                return false;
            }
        }
        return true;
    }

    /**
     * Get the keys for all of the input and files.
     *
     * @return array
     */
    public function keys()
    {
        return array_merge(array_keys($this->input()), $this->files->keys());
    }

    /**
     * Get a subset containing the provided keys with values from the input data.
     *
     * @param  array|mixed $keys
     *
     * @return array
     */
    public function only($keys)
    {
        $results = [];
        $input = $this->all();
        $placeholder = new stdClass;
        foreach (is_array($keys) ? $keys : func_get_args() as $key) {
            $value = data_get($input, $key, $placeholder);
            if ($value !== $placeholder) {
                Arr::set($results, $key, $value);
            }
        }
        return $results;
    }

    /**
     * Get all of the input except for a specified array of items.
     *
     * @param  array|mixed $keys
     *
     * @return array
     */
    public function except($keys)
    {
        $keys = is_array($keys) ? $keys : func_get_args();
        $results = $this->all();
        Arr::forget($results, $keys);
        return $results;
    }

    /**
     * Retrieve a request payload item from the request.
     *
     * @param  string            $key
     * @param  string|array|null $default
     *
     * @return string|array
     */
    public function post($key = null, $default = null)
    {
        return $this->retrieveItem('request', $key, $default);
    }

    /**
     * Determine if a cookie is set on the request.
     *
     * @param  string $key
     *
     * @return bool
     */
    public function hasCookie($key)
    {
        return ! is_null($this->cookie($key));
    }

    /**
     * Retrieve a cookie from the request.
     *
     * @param  string            $key
     * @param  string|array|null $default
     *
     * @return string|array
     */
    public function cookie($key = null, $default = null)
    {
        return $this->retrieveItem('cookies', $key, $default);
    }

    /**
     * Determine if the uploaded data contains a file.
     *
     * @param  string $key
     *
     * @return bool
     */
    public function hasFile($key)
    {
        if (! is_array($files = $this->file($key))) {
            $files = [$files];
        }
        foreach ($files as $file) {
            if ($this->isValidFile($file)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Retrieve a file from the request.
     *
     * @param  string $key
     * @param  mixed  $default
     *
     * @return \Illuminate\Http\UploadedFile|array|null
     */
    public function file($key = null, $default = null)
    {
        return data_get($this->allFiles(), $key, $default);
    }

    /**
     * Get the request method.
     *
     * @return string
     */
    public function method()
    {
        return $this->getMethod();
    }

    /**
     * Get the root URL for the application.
     *
     * @return string
     */
    public function root()
    {
        return rtrim($this->getSchemeAndHttpHost() . $this->getBaseUrl(), '/');
    }

    /**
     * Get the full URL for the request with the added query string parameters.
     *
     * @param  array $query
     *
     * @return string
     */
    public function fullUrlWithQuery(array $query)
    {
        $question = $this->getBaseUrl() . $this->getPathInfo() == '/' ? '/?' : '?';
        return count($this->query()) > 0
            ? $this->url() . $question . http_build_query(array_merge($this->query(), $query))
            : $this->fullUrl() . $question . http_build_query($query);
    }

    /**
     * Retrieve a query string item from the request.
     *
     * @param  string            $key
     * @param  string|array|null $default
     *
     * @return string|array
     */
    public function query($key = null, $default = null)
    {
        return $this->retrieveItem('query', $key, $default);
    }

    /**
     * Get the URL (no query string) for the request.
     *
     * @return string
     */
    public function url()
    {
        return rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/');
    }

    /**
     * Get the full URL for the request.
     *
     * @return string
     */
    public function fullUrl()
    {
        $query = $this->getQueryString();
        $question = $this->getBaseUrl() . $this->getPathInfo() == '/' ? '/?' : '?';
        return $query ? $this->url() . $question . $query : $this->url();
    }

    /**
     * Get a segment from the URI (1 based index).
     *
     * @param  int         $index
     * @param  string|null $default
     *
     * @return string|null
     */
    public function segment($index, $default = null)
    {
        return Arr::get($this->segments(), $index - 1, $default);
    }

    /**
     * Get all of the segments for the request path.
     *
     * @return array
     */
    public function segments()
    {
        $segments = explode('/', $this->decodedPath());
        return array_values(array_filter($segments, function ($value) {
            return $value !== '';
        }));
    }

    /**
     * Get the current decoded path info for the request.
     *
     * @return string
     */
    public function decodedPath()
    {
        return rawurldecode($this->path());
    }

    /**
     * Get the current path info for the request.
     *
     * @return string
     */
    public function path()
    {
        $pattern = trim($this->getPathInfo(), '/');
        return $pattern == '' ? '/' : $pattern;
    }

    /**
     * Determine if the request is over HTTPS.
     *
     * @return bool
     */
    public function secure()
    {
        return $this->isSecure();
    }

    /**
     * Get the client IP address.
     *
     * @return string
     */
    public function ip()
    {
        return $this->getClientIp();
    }

    /**
     * Get the client IP addresses.
     *
     * @return array
     */
    public function ips()
    {
        return $this->getClientIps();
    }

    /**
     * Get the client user agent.
     *
     * @return string
     */
    public function userAgent()
    {
        return $this->headers->get('User-Agent');
    }

    /**
     * Merge new input into the current request's input array.
     *
     * @param  array $input
     *
     * @return \Nur\Http\Request
     */
    public function merge(array $input)
    {
        $this->getInputSource()->add($input);
        return $this;
    }

    /**
     * Replace the input for the current request.
     *
     * @param  array $input
     *
     * @return \Nur\Http\Request
     */
    public function replace(array $input)
    {
        $this->getInputSource()->replace($input);
        return $this;
    }

    /**
     * This method belongs to Symfony HttpFoundation and is not usually needed when using Nur FW.
     *
     * Instead, you may use the "input" method.
     *
     * @param  string $key
     * @param  mixed  $default
     *
     * @return mixed
     */
    public function get($key, $default = null)
    {
        return parent::get($key, $default);
    }

    /**
     * Get all of the input and files for the request.
     *
     * @return array
     */
    public function toArray()
    {
        return $this->all();
    }

    /**
     * Check if an input element is set on the request.
     *
     * @param  string $key
     *
     * @return bool
     */
    public function __isset($key)
    {
        return ! is_null($this->__get($key));
    }

    /**
     * Get an input element from the request.
     *
     * @param  string $key
     *
     * @return mixed|void
     */
    public function __get($key)
    {
        if (array_key_exists($key, $this->all())) {
            return data_get($this->all(), $key);
        }

        return;
    }

    /**
     * Determine if the current request probably expects a JSON response.
     *
     * @return bool
     */
    public function expectsJson()
    {
        return ($this->ajax() && ! $this->pjax() && $this->acceptsAnyContentType()) || $this->wantsJson();
    }

    /**
     * Determine if the request is the result of an AJAX call.
     *
     * @return bool
     */
    public function ajax()
    {
        return $this->isXmlHttpRequest();
    }

    /**
     * Determine if the request is the result of an PJAX call.
     *
     * @return bool
     */
    public function pjax()
    {
        return $this->headers->get('X-PJAX') == true;
    }

    /**
     * Determine if the current request accepts any content type.
     *
     * @return bool
     */
    public function acceptsAnyContentType()
    {
        $acceptable = $this->getAcceptableContentTypes();
        return count($acceptable) === 0 || (
                isset($acceptable[0]) && ($acceptable[0] === '*/*' || $acceptable[0] === '*')
            );
    }

    /**
     * Determine if the current request is asking for JSON.
     *
     * @return bool
     */
    public function wantsJson()
    {
        $acceptable = $this->getAcceptableContentTypes();
        return isset($acceptable[0]) && Str::contains($acceptable[0], ['/json', '+json']);
    }

    /** Illuminate\Http\Concerns\InteractsWithContentTypes; */

    /**
     * Return the most suitable content type from the given array based on content negotiation.
     *
     * @param  string|array $contentTypes
     *
     * @return string|null
     */
    public function prefers($contentTypes)
    {
        $accepts = $this->getAcceptableContentTypes();
        $contentTypes = (array)$contentTypes;
        foreach ($accepts as $accept) {
            if (in_array($accept, ['*/*', '*'])) {
                return $contentTypes[0];
            }
            foreach ($contentTypes as $contentType) {
                $type = $contentType;
                if (! is_null($mimeType = $this->getMimeType($contentType))) {
                    $type = $mimeType;
                }
                if ($this->matchesType($type, $accept) || $accept === strtok($type, '/') . '/*') {
                    return $contentType;
                }
            }
        }
    }

    /**
     * Determine if the given content types match.
     *
     * @param  string $actual
     * @param  string $type
     *
     * @return bool
     */
    public static function matchesType($actual, $type)
    {
        if ($actual === $type) {
            return true;
        }
        $split = explode('/', $actual);
        return isset($split[1]) && preg_match('#' . preg_quote($split[0], '#') . '/.+\+' . preg_quote($split[1],
                    '#') . '#', $type);
    }

    /**
     * Determines whether a request accepts JSON.
     *
     * @return bool
     */
    public function acceptsJson()
    {
        return $this->accepts('application/json');
    }

    /**
     * Determines whether the current requests accepts a given content type.
     *
     * @param  string|array $contentTypes
     *
     * @return bool
     */
    public function accepts($contentTypes)
    {
        $accepts = $this->getAcceptableContentTypes();
        if (count($accepts) === 0) {
            return true;
        }
        $types = (array)$contentTypes;
        foreach ($accepts as $accept) {
            if ($accept === '*/*' || $accept === '*') {
                return true;
            }
            foreach ($types as $type) {
                if ($this->matchesType($accept, $type) || $accept === strtok($type, '/') . '/*') {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * Determines whether a request accepts HTML.
     *
     * @return bool
     */
    public function acceptsHtml()
    {
        return $this->accepts('text/html');
    }

    /**
     * Get the data format expected in the response.
     *
     * @param  string $default
     *
     * @return string
     */
    public function format($default = 'html')
    {
        foreach ($this->getAcceptableContentTypes() as $type) {
            if ($format = $this->getFormat($type)) {
                return $format;
            }
        }
        return $default;
    }

    /**
     * Retrieve a parameter item from a given source.
     *
     * @param  string            $source
     * @param  string            $key
     * @param  string|array|null $default
     *
     * @return string|array
     */
    protected function retrieveItem($source, $key, $default)
    {
        if (is_null($key)) {
            return $this->$source->all();
        }
        return $this->$source->get($key, $default);
    }

    /**
     * Get the input source for the request.
     *
     * @return \Symfony\Component\HttpFoundation\ParameterBag
     */
    protected function getInputSource()
    {
        if ($this->isJson()) {
            return $this->json();
        }

        return in_array($this->getRealMethod(), ['GET', 'HEAD']) ? $this->query : $this->request;
    }

    /**
     * Determine if the given input key is an empty string for "has".
     *
     * @param  string $key
     *
     * @return bool
     */
    protected function isEmptyString($key)
    {
        $value = $this->input($key);
        return ! is_bool($value) && ! is_array($value) && trim((string)$value) === '';
    }

    /**
     * Check that the given file is a valid file instance.
     *
     * @param  mixed $file
     *
     * @return bool
     */
    protected function isValidFile($file)
    {
        return $file instanceof SplFileInfo && $file->getPath() !== '';
    }
}


<?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 RollbackCommand extends AbstractCommand
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        parent::configure();

        $this->setName('rollback')
             ->addOption('--target', '-t', InputArgument::OPTIONAL, 'The version number to rollback to')
             ->setDescription('Rollback last, or to a specific migration')
             ->setHelp(<<<EOT
The <info>rollback</info> command reverts the last migration, or optionally up to a specific version

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

EOT
        );
    }

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

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

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

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

        // Check we have at least 1 migration to revert
        if (empty($versions) || $version == end($versions)) {
            $output->writeln("<error>-Error</error> No migrations to rollback.");
            return;
        }

        // If no target version was supplied, revert the last migration
        if (null === $version) {
            // Get the migration before the last run migration
            $prev = count($versions) - 2;
            $version = $prev >= 0 ? $versions[$prev] : 0;
        } else {
            // Get the first migration number
            $first = reset($versions);

            // If the target version is before the first migration, revert all migrations
            if ($version < $first) {
                $version = 0;
            }
        }

        // Check the target version exists
        if (0 !== $version && !isset($migrations[$version])) {
            $output->writeln("<error>-Error</error> Migration version ($version) not found.");
            return;
        }

        // Revert the migration(s)
        $container = $this->getContainer();
        krsort($migrations);
        foreach($migrations as $migration) {
            if ($migration->getVersion() <= $version) {
                break;
            }

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


<?php

namespace Nur\Console;

class Command
{
    protected $app;

    protected $commandList = [
        'Nur\Console\Commands\App\UpCommand',
        'Nur\Console\Commands\App\DownCommand',
        'Nur\Console\Commands\App\StatusCommand',
        'Nur\Console\Commands\App\ServeCommand',
        'Nur\Console\Commands\App\KeygenCommand',

        'Nur\Console\Commands\Cache\RouteCommand',
        'Nur\Console\Commands\Cache\ConfigCommand',

        'Nur\Console\Commands\Clear\CacheCommand',
        'Nur\Console\Commands\Clear\LogCommand',
        'Nur\Console\Commands\Clear\RouteCommand',
        'Nur\Console\Commands\Clear\ConfigCommand',

        'Nur\Console\Commands\Make\ControllerCommand',
        'Nur\Console\Commands\Make\ModelCommand',
        'Nur\Console\Commands\Make\MiddlewareCommand',
        'Nur\Console\Commands\Make\ResourceCommand',

        'Nur\Console\Commands\Database\CreateCommand',
        'Nur\Console\Commands\Database\RemoveCommand',
        'Nur\Console\Commands\Database\ListCommand',

        'Nur\Console\Commands\Remove\ControllerCommand',
        'Nur\Console\Commands\Remove\ModelCommand',
        'Nur\Console\Commands\Remove\MiddlewareCommand',
    ];

    protected $migrationCommands = [
        'Nur\Console\Commands\Migrations\CheckCommand',
        'Nur\Console\Commands\Migrations\DownCommand',
        'Nur\Console\Commands\Migrations\GenerateCommand',
        'Nur\Console\Commands\Migrations\MigrateCommand',
        'Nur\Console\Commands\Migrations\RedoCommand',
        'Nur\Console\Commands\Migrations\RollbackCommand',
        'Nur\Console\Commands\Migrations\StatusCommand',
        'Nur\Console\Commands\Migrations\UpCommand',
        'Nur\Console\Commands\Migrations\RemoveCommand',
    ];

    /**
     * Set console application.
     *
     * @param $app
     *
     * @return null
     */
    function __construct($app)
    {
        $this->app = $app;
        $this->generate();
    }

    /**
     * Genereta all Command class.
     *
     * @return void
     */
    public function generate()
    {
        foreach ($this->commandList as $key => $value) {
            $this->app->add(new $value);
        }

        foreach ($this->migrationCommands as $command) {
            $newCommand = new $command;
            $newCommand->setName("migration:" . $newCommand->getName());
            $this->app->add($newCommand);
        }
    }

    /**
     * Run console commands.
     *
     * @return void
     */
    public function run()
    {
        $this->app->run();
        exit();
    }
}


<?php

namespace Nur\Components\Builder\Providers;

use Nur\Uri\Uri;

class HtmlProvider
{
    /**
     * The URI generator instance.
     *
     * @var \Nur\Uri\Uri;
     */
    protected $uri;

    /**
     * Create a new HTML builder instance.
     *
     * @param $uri
     */
    public function __construct(Uri $uri)
    {
        $this->uri = $uri;
    }

    /**
     * Convert an HTML string to entities.
     *
     * @param string $value
     *
     * @return string
     */
    public function entities($value)
    {
        return htmlentities($value, ENT_QUOTES, 'UTF-8', false);
    }

    /**
     * Convert entities to HTML characters.
     *
     * @param string $value
     *
     * @return string
     */
    public function decode($value)
    {
        return html_entity_decode($value, ENT_QUOTES, 'UTF-8');
    }

    /**
     * Generate a link to a JavaScript file.
     *
     * @param string $url
     * @param array  $attributes
     * @param bool   $secure
     *
     * @return string
     */
    public function script($url, $attributes = [], $secure = null)
    {
        $attributes['src'] = $this->uri->assets($url, $secure);

        return $this->toHtmlString('' . PHP_EOL);
    }

    /**
     * Generate a link to a CSS file.
     *
     * @param string $url
     * @param array  $attributes
     * @param bool   $secure
     *
     * @return string
     */
    public function style($url, $attributes = [], $secure = null)
    {
        $defaults = ['media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet'];

        $attributes = array_merge($attributes, $defaults);

        $attributes['href'] = $this->uri->assets($url, $secure);

        return $this->toHtmlString('<link' . $this->attributes($attributes) . '>' . PHP_EOL);
    }

    /**
     * Generate an HTML image element.
     *
     * @param string $url
     * @param string $alt
     * @param array  $attributes
     * @param bool   $secure
     *
     * @return string
     */
    public function image($url, $alt = null, $attributes = [], $secure = null)
    {
        $attributes['alt'] = $alt;

        return $this->toHtmlString('uri->assets($url,
                $secure) . '"' . $this->attributes($attributes) . '>');
    }

    /**
     * Generate a link to a Favicon file.
     *
     * @param string $url
     * @param array  $attributes
     * @param bool   $secure
     *
     * @return string
     */
    public function favicon($url, $attributes = [], $secure = null)
    {
        $defaults = ['rel' => 'shortcut icon', 'type' => 'image/x-icon'];

        $attributes = array_merge($attributes, $defaults);

        $attributes['href'] = $this->uri->assets($url, $secure);

        return $this->toHtmlString('<link' . $this->attributes($attributes) . '>' . PHP_EOL);
    }

    /**
     * Generate a HTML link.
     *
     * @param string $url
     * @param string $title
     * @param array  $attributes
     * @param bool   $secure
     * @param bool   $escape
     *
     * @return string
     */
    public function link($url, $title = null, $attributes = [], $secure = null, $escape = true)
    {
        $url = $this->uri->base($url, $secure);

        if (is_null($title) || $title === false) {
            $title = $url;
        }

        if ($escape) {
            $title = $this->entities($title);
        }

        return $this->toHtmlString('attributes($attributes) . '>' . $title . '');
    }

    /**
     * Generate a HTTPS HTML link.
     *
     * @param string $url
     * @param string $title
     * @param array  $attributes
     *
     * @return string
     */
    public function secureLink($url, $title = null, $attributes = [])
    {
        return $this->link($url, $title, $attributes, true);
    }

    /**
     * Generate a HTML link to an asset.
     *
     * @param string $url
     * @param string $title
     * @param array  $attributes
     * @param bool   $secure
     *
     * @return string
     */
    public function linkAsset($url, $title = null, $attributes = [], $secure = null)
    {
        $url = $this->uri->assets($url, $secure);

        return $this->link($url, $title ?: $url, $attributes, $secure);
    }

    /**
     * Generate a HTTPS HTML link to an asset.
     *
     * @param string $url
     * @param string $title
     * @param array  $attributes
     *
     * @return string
     */
    public function linkSecureAsset($url, $title = null, $attributes = [])
    {
        return $this->linkAsset($url, $title, $attributes, true);
    }

    /**
     * Generate a HTML link to a named route.
     *
     * @param string $name
     * @param string $title
     * @param array  $parameters
     * @param array  $attributes
     *
     * @return string
     */
    public function linkRoute($name, $title = null, $parameters = [], $attributes = [])
    {
        return $this->link($this->uri->route($name, $parameters), $title, $attributes);
    }

    /**
     * Generate a HTML link to an email address.
     *
     * @param string $email
     * @param string $title
     * @param array  $attributes
     * @param bool   $escape
     *
     * @return string
     */
    public function mailto($email, $title = null, $attributes = [], $escape = true)
    {
        $email = $this->email($email);

        $title = $title ?: $email;

        if ($escape) {
            $title = $this->entities($title);
        }

        $email = $this->obfuscate('mailto:') . $email;

        return $this->toHtmlString('attributes($attributes) . '>' . $title . '');
    }

    /**
     * Obfuscate an e-mail address to prevent spam-bots from sniffing it.
     *
     * @param string $email
     *
     * @return string
     */
    public function email($email)
    {
        return str_replace('@', '@', $this->obfuscate($email));
    }

    /**
     * Generates non-breaking space entities based on number supplied.
     *
     * @param int $num
     *
     * @return string
     */
    public function nbsp($num = 1)
    {
        return str_repeat(' ', $num);
    }

    /**
     * Generate an ordered list of items.
     *
     * @param array $list
     * @param array $attributes
     *
     * @return string|string
     */
    public function ol($list, $attributes = [])
    {
        return $this->listing('ol', $list, $attributes);
    }

    /**
     * Generate an un-ordered list of items.
     *
     * @param array $list
     * @param array $attributes
     *
     * @return string|string
     */
    public function ul($list, $attributes = [])
    {
        return $this->listing('ul', $list, $attributes);
    }

    /**
     * Generate a description list of items.
     *
     * @param array $list
     * @param array $attributes
     *
     * @return string
     */
    public function dl(array $list, array $attributes = [])
    {
        $attributes = $this->attributes($attributes);

        $html = "
";

        foreach ($list as $key => $value) {
            $value = (array)$value;

            $html .= "
$key
";

            foreach ($value as $v_key => $v_value) {
                $html .= "
$v_value
";
            }
        }

        $html .= '
';

        return $this->toHtmlString($html);
    }

    /**
     * Build an HTML attribute string from an array.
     *
     * @param array $attributes
     *
     * @return string
     */
    public function attributes($attributes)
    {
        $html = [];

        foreach ((array)$attributes as $key => $value) {
            $element = $this->attributeElement($key, $value);

            if (! is_null($element)) {
                $html[] = $element;
            }
        }

        return count($html) > 0 ? ' ' . implode(' ', $html) : '';
    }

    /**
     * Obfuscate a string to prevent spam-bots from sniffing it.
     *
     * @param string $value
     *
     * @return string
     */
    public function obfuscate($value)
    {
        $safe = '';

        foreach (str_split($value) as $letter) {
            if (ord($letter) > 128) {
                return $letter;
            }

            // To properly obfuscate the value, we will randomly convert each letter to
            // its entity or hexadecimal representation, keeping a bot from sniffing
            // the randomly obfuscated letters out of the string on the responses.
            switch (rand(1, 3)) {
                case 1:
                    $safe .= '&#' . ord($letter) . ';';
                    break;

                case 2:
                    $safe .= '&#x' . dechex(ord($letter)) . ';';
                    break;

                case 3:
                    $safe .= $letter;
            }
        }

        return $safe;
    }

    /**
     * Generate a meta tag.
     *
     * @param string $name
     * @param string $content
     * @param array  $attributes
     *
     * @return string
     */
    public function meta($name, $content, array $attributes = [])
    {
        $defaults = compact('name', 'content');

        $attributes = array_merge($defaults, $attributes);

        return $this->toHtmlString('<meta' . $this->attributes($attributes) . '>' . PHP_EOL);
    }

    /**
     * Generate an html tag.
     *
     * @param string $tag
     * @param mixed  $content
     * @param array  $attributes
     *
     * @return string
     */
    public function tag($tag, $content, array $attributes = [])
    {
        $content = is_array($content) ? implode(PHP_EOL, $content) : $content;
        return $this->toHtmlString('<' . $tag . $this->attributes($attributes) . '>' . PHP_EOL . $this->toHtmlString($content) . PHP_EOL . '</' . $tag . '>' . PHP_EOL);
    }

    /**
     * Create a listing HTML element.
     *
     * @param string $type
     * @param array  $list
     * @param array  $attributes
     *
     * @return string|string
     */
    protected function listing($type, $list, $attributes = [])
    {
        $html = '';

        if (count($list) == 0) {
            return $html;
        }

        // Essentially we will just spin through the list and build the list of the HTML
        // elements from the array. We will also handled nested lists in case that is
        // present in the array. Then we will build out the final listing elements.
        foreach ($list as $key => $value) {
            $html .= $this->listingElement($key, $type, $value);
        }

        $attributes = $this->attributes($attributes);

        return $this->toHtmlString("<{$type}{$attributes}>{$html}</{$type}>");
    }

    /**
     * Create the HTML for a listing element.
     *
     * @param mixed  $key
     * @param string $type
     * @param mixed  $value
     *
     * @return string
     */
    protected function listingElement($key, $type, $value)
    {
        if (is_array($value)) {
            return $this->nestedListing($key, $type, $value);
        } else {
            return '
' . e($value) . '
';
        }
    }

    /**
     * Create the HTML for a nested listing attribute.
     *
     * @param mixed  $key
     * @param string $type
     * @param mixed  $value
     *
     * @return string
     */
    protected function nestedListing($key, $type, $value)
    {
        if (is_int($key)) {
            return $this->listing($type, $value);
        } else {
            return '
' . $key . $this->listing($type, $value) . '
';
        }
    }

    /**
     * Build a single attribute element.
     *
     * @param string $key
     * @param string $value
     *
     * @return string
     */
    protected function attributeElement($key, $value)
    {
        // For numeric keys we will assume that the value is a boolean attribute
        // where the presence of the attribute represents a true value and the
        // absence represents a false value.
        // This will convert HTML attributes such as "required" to a correct
        // form instead of using incorrect numerics.
        if (is_numeric($key)) {
            return $value;
        }

        // Treat boolean attributes as HTML properties
        if (is_bool($value) && $key != 'value') {
            return $value ? $key : '';
        }

        if (! is_null($value)) {
            return $key . '="' . e($value) . '"';
        }
    }

    /**
     * Transform the string to an Html serializable object
     *
     * @param $html
     *
     * @return string
     */
    protected function toHtmlString($html)
    {
        return ($html);
    }
}


<?php

namespace Nur\Console\Commands\Migrations;

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

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

        $this->setName('generate')
             ->addArgument('name', InputArgument::REQUIRED, 'The name for the migration')
             ->addOption('--table', '-t', InputOption::VALUE_OPTIONAL, 'Migration Table name (Default: null)')
             ->setDescription('Generate a new migration')
             ->setHelp(<<<EOT
The <info>generate</info> command creates a new migration with the name and path specified

<info>migration:generate TestMigration</info>

EOT
        );
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->bootstrap($input, $output);
        $tableName = $input->hasParameterOption('--table') !== false
            ? $input->getOption('table')
            : '';

        $path = $this->container['phpmig.migrations_path'];
        $locator = new FileLocator(array());
        $path    = $locator->locate($path, base_path(), $first = true);

        if (!is_writeable($path)) {
            throw new \InvalidArgumentException(sprintf(
                'The directory "%s" is not writeable',
                $path
            ));
        }

        $path = realpath($path);
        $migrationName = $this->transMigName($input->getArgument('name'));
        $basename  = date('YmdHis') . '_' . $migrationName . '.php';
        $path = $path . DIRECTORY_SEPARATOR . $basename;
        if (file_exists($path)) {
            throw new \InvalidArgumentException(sprintf('The file "%s" already exists', $path));
        }

        $className = $this->migrationToClassName($migrationName);
        $schema = '$this';
        $blueprint = '$table';
        $contents = <<<PHP
<?php

use Nur\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;

class $className extends Migration
{
    /* Do the migration */
    public function up()
    {
        {$schema}->schema->create('{$tableName}', function(Blueprint $blueprint) {
            {$blueprint}->increments('id');

            {$blueprint}->timestamps();
            {$blueprint}->enum('status', [0, 1]);
        });
    }

    /* Undo the migration */
    public function down()
    {
        {$schema}->schema->dropIfExists('{$tableName}');
    }
}

PHP;
        if (false === file_put_contents($path, $contents)) {
            throw new \RuntimeException(sprintf('The file "%s" could not be written to', $path));
        }

        $output->writeln(
            '<info>+Success!</info> ' .
            '"'.str_replace([getcwd(), 'database', 'migrations', '/', '\\', '.php'], '', $path).'" migration generated.'
        );

        return;
    }

    protected function transMigName($migrationName)
    {
        if (preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $migrationName)) {
            return $migrationName;
        }
        return 'mig' . $migrationName;
    }
}


<?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 UpCommand extends AbstractCommand
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        parent::configure();

        $this->setName('up')
             ->addArgument('version', InputArgument::REQUIRED, 'The version number for the migration')
             ->setDescription('Run a specific migration')
             ->setHelp(<<<EOT
The <info>up</info> command runs a specific migration

<info>migration:up 20111018185121</info>

EOT
        );
    }

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

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

        $version = $input->getArgument('version');

        if (in_array($version, $versions)) {
            $output->writeLn('<error>-Error!</error> "'.$version.'" migration status already active.');
            return;
        }

        if (!isset($migrations[$version])) {
            $output->writeLn('<error>-Error!</error> "'.$version.'" migration not found. Please check migration ID.');
            return;
        }

        $container = $this->getContainer();
        $container['phpmig.migrator']->up($migrations[$version]);
    }
}


<?php

namespace Nur\Console\Commands\App;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Nur\Encryption\Encrypter;

class KeygenCommand extends Command
{
    protected function configure()
    {
        $this
            ->setName('app:keygen')
            ->setDescription("Set the application key.")
            ->setHelp("This command makes you to create or re-create application key.")
            ->addOption('--show', '-s', InputOption::VALUE_OPTIONAL, 'Display the key instead of modifying files');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $key = $this->generateRandomKey();
        if ($input->hasParameterOption('--show') !== false) {
            return $output->writeln('<comment>'.$key.'</comment>');
        }

        // Next, we will replace the application key in the environment file so it is
        // automatically setup for this developer. This key gets generated using a
        // secure random byte generator and is later base64 encoded for storage.
        if (! $this->setKeyInEnvironmentFile($key, $input, $output)) {
            return;
        }

        config()->set('app.key', $key);
        $output->writeln('<info>+Success!</info> Application key set successfully.');
    }

    /**
     * Generate a random key for the application.
     *
     * @return string
     */
    protected function generateRandomKey()
    {
        return 'base64:'.base64_encode(
            Encrypter::generateKey(config('app.cipher'))
        );
    }

    /**
     * Set the application key in the environment file.
     *
     * @param  string  $key
     * @return bool
     */
    protected function setKeyInEnvironmentFile($key, $input, $output)
    {
        $currentKey = config('app.key');

        $helper = $this->getHelper('question');
        $question = new ConfirmationQuestion('Application key will re-generate. Are you sure?: ', false);
        if (strlen($currentKey) !== 0 && (! $helper->ask($input, $output, $question))) {
            return false;
        }

        $this->writeNewEnvironmentFileWith($key);
        return true;
    }

    /**
     * Write a new environment file with the given key.
     *
     * @param  string  $key
     * @return void
     */
    protected function writeNewEnvironmentFileWith($key)
    {
        file_put_contents(base_path('.env'), preg_replace(
            $this->keyReplacementPattern(),
            'APP_KEY='.$key,
            file_get_contents(base_path('.env'))
        ));
    }

    /**
     * Get a regex pattern that will match env APP_KEY with any random key.
     *
     * @return string
     */
    protected function keyReplacementPattern()
    {
        $escaped = preg_quote('='.config('app.key'), '/');
        return "/^APP_KEY{$escaped}/m";
    }
}


<?php

namespace Nur\Load;

use Nur\Exception\ExceptionHandler;

class Load
{
    /**
     * Load view file.
     *
     * @param string $name
     * @param array  $data
     *
     * @return mixed
     *
     * @throws
     */
    public function view($name, array $data = [])
    {
        $file = app_path('Views' . DIRECTORY_SEPARATOR . $name . '.php');
        if (file_exists($file)) {
            extract($data);
            require $file;
            return ob_get_clean();
        }

        throw new ExceptionHandler('Oppss! File not found.', 'View::' . $name . ' not found.');
    }

    /**
     * Load helper file.
     *
     * @param string $name
     * @param string $directory
     * @return mixed
     *
     * @throws
     */
    public function helper($name, $directory = 'Helpers')
    {
        $file = app_path($directory . DIRECTORY_SEPARATOR . $name . '.php');
        if (file_exists($file)) {
            return require $file;
        }

        throw new ExceptionHandler('Oppss! File not found.', 'Helper::' . $name . ' not found.');
    }
}


<?php

namespace Nur\Event;

use Nur\Exception\ExceptionHandler;

class Event
{
    /**
     * Trigger an event
     *
     * @param string $event
     * @param array  $params
     * @param string $method
     *
     * @return mixed
     * @throws ExceptionHandler
     */
    public function trigger($event, array $params = [], $method = 'handle')
    {
        $listeners = config('services.listeners');
        foreach ($listeners[$event] as $listener) {
            if (! class_exists($listener)) {
                throw new ExceptionHandler('Event class not found.', $listener);
            }

            if (! method_exists($listener, $method)) {
                throw new ExceptionHandler('Method not found in Event class.', $listener . '::' . $method . '()');
            }

            call_user_func_array([new $listener, $method], $params);
        }
    }
}


<?php
/**
 * TaskInstanceAttributes
 *
 * 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;

/**
 * TaskInstanceAttributes 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 TaskInstanceAttributes implements ArrayAccess
{
    /**
      * The original name of the model.
      * @var string
      */
    protected static $swaggerModelName = 'TaskInstance_attributes';

    /**
      * Array of property to type mappings. Used for (de)serialization
      * @var string[]
      */
    protected static $swaggerTypes = array(
        'task_id' => 'string',
        'instance_id' => 'string',
        'group_id' => 'string',
        'user_id' => 'string',
        'status' => 'string',
        'priority' => 'string',
        'delegate_date' => 'string',
        'start_date' => 'string',
        'finish_date' => 'string',
        'task_due_date' => 'string',
        'risk_date' => 'string',
        'duration' => 'int',
        'instance_overdue_percentage' => 'double',
        'data' => 'string',
        'data_model' => '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(
        'task_id' => 'task_id',
        'instance_id' => 'instance_id',
        'group_id' => 'group_id',
        'user_id' => 'user_id',
        'status' => 'status',
        'priority' => 'priority',
        'delegate_date' => 'delegate_date',
        'start_date' => 'start_date',
        'finish_date' => 'finish_date',
        'task_due_date' => 'task_due_date',
        'risk_date' => 'risk_date',
        'duration' => 'duration',
        'instance_overdue_percentage' => 'instance_overdue_percentage',
        'data' => 'data',
        'data_model' => 'dataModel',
        '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(
        'task_id' => 'setTaskId',
        'instance_id' => 'setInstanceId',
        'group_id' => 'setGroupId',
        'user_id' => 'setUserId',
        'status' => 'setStatus',
        'priority' => 'setPriority',
        'delegate_date' => 'setDelegateDate',
        'start_date' => 'setStartDate',
        'finish_date' => 'setFinishDate',
        'task_due_date' => 'setTaskDueDate',
        'risk_date' => 'setRiskDate',
        'duration' => 'setDuration',
        'instance_overdue_percentage' => 'setInstanceOverduePercentage',
        'data' => 'setData',
        'data_model' => 'setDataModel',
        '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(
        'task_id' => 'getTaskId',
        'instance_id' => 'getInstanceId',
        'group_id' => 'getGroupId',
        'user_id' => 'getUserId',
        'status' => 'getStatus',
        'priority' => 'getPriority',
        'delegate_date' => 'getDelegateDate',
        'start_date' => 'getStartDate',
        'finish_date' => 'getFinishDate',
        'task_due_date' => 'getTaskDueDate',
        'risk_date' => 'getRiskDate',
        'duration' => 'getDuration',
        'instance_overdue_percentage' => 'getInstanceOverduePercentage',
        'data' => 'getData',
        'data_model' => 'getDataModel',
        'created_at' => 'getCreatedAt',
        'updated_at' => 'getUpdatedAt'
    );

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

    const STATUS_INITIAL = 'INITIAL';
    const STATUS_DELEGATED = 'DELEGATED';
    const STATUS_STARTED = 'STARTED';
    const STATUS_CANCELLED = 'CANCELLED';
    const STATUS_FINISHED = 'FINISHED';
    const STATUS_COMPLETE = 'COMPLETE';
    const STATUS_PAUSED = 'PAUSED';
    const PRIORITY__1 = '1';
    const PRIORITY__2 = '2';
    const PRIORITY__3 = '3';
    const PRIORITY__4 = '4';
    const PRIORITY__5 = '5';

    /**
     * Gets allowable values of the enum
     * @return string[]
     */
    public function getStatusAllowableValues()
    {
        return [
            self::STATUS_INITIAL,
            self::STATUS_DELEGATED,
            self::STATUS_STARTED,
            self::STATUS_CANCELLED,
            self::STATUS_FINISHED,
            self::STATUS_COMPLETE,
            self::STATUS_PAUSED,
        ];
    }

    /**
     * Gets allowable values of the enum
     * @return string[]
     */
    public function getPriorityAllowableValues()
    {
        return [
            self::PRIORITY__1,
            self::PRIORITY__2,
            self::PRIORITY__3,
            self::PRIORITY__4,
            self::PRIORITY__5,
        ];
    }

    /**
     * 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['task_id'] = isset($data['task_id']) ? $data['task_id'] : null;
        $this->container['instance_id'] = isset($data['instance_id']) ? $data['instance_id'] : null;
        $this->container['group_id'] = isset($data['group_id']) ? $data['group_id'] : null;
        $this->container['user_id'] = isset($data['user_id']) ? $data['user_id'] : null;
        $this->container['status'] = isset($data['status']) ? $data['status'] : 'INITIAL';
        $this->container['priority'] = isset($data['priority']) ? $data['priority'] : '3';
        $this->container['delegate_date'] = isset($data['delegate_date']) ? $data['delegate_date'] : null;
        $this->container['start_date'] = isset($data['start_date']) ? $data['start_date'] : null;
        $this->container['finish_date'] = isset($data['finish_date']) ? $data['finish_date'] : null;
        $this->container['task_due_date'] = isset($data['task_due_date']) ? $data['task_due_date'] : null;
        $this->container['risk_date'] = isset($data['risk_date']) ? $data['risk_date'] : null;
        $this->container['duration'] = isset($data['duration']) ? $data['duration'] : null;
        $this->container['instance_overdue_percentage'] = isset($data['instance_overdue_percentage']) ? $data['instance_overdue_percentage'] : null;
        $this->container['data'] = isset($data['data']) ? $data['data'] : null;
        $this->container['data_model'] = isset($data['data_model']) ? $data['data_model'] : 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['task_id'] === null) {
            $invalid_properties[] = "'task_id' can't be null";
        }
        if ($this->container['instance_id'] === null) {
            $invalid_properties[] = "'instance_id' can't be null";
        }
        if ($this->container['status'] === null) {
            $invalid_properties[] = "'status' can't be null";
        }
        $allowed_values = array("INITIAL", "DELEGATED", "STARTED", "CANCELLED", "FINISHED", "COMPLETE", "PAUSED");
        if (!in_array($this->container['status'], $allowed_values)) {
            $invalid_properties[] = "invalid value for 'status', must be one of #{allowed_values}.";
        }

        if ($this->container['priority'] === null) {
            $invalid_properties[] = "'priority' can't be null";
        }
        $allowed_values = array("1", "2", "3", "4", "5");
        if (!in_array($this->container['priority'], $allowed_values)) {
            $invalid_properties[] = "invalid value for 'priority', must be one of #{allowed_values}.";
        }

        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['task_id'] === null) {
            return false;
        }
        if ($this->container['instance_id'] === null) {
            return false;
        }
        if ($this->container['status'] === null) {
            return false;
        }
        $allowed_values = array("INITIAL", "DELEGATED", "STARTED", "CANCELLED", "FINISHED", "COMPLETE", "PAUSED");
        if (!in_array($this->container['status'], $allowed_values)) {
            return false;
        }
        if ($this->container['priority'] === null) {
            return false;
        }
        $allowed_values = array("1", "2", "3", "4", "5");
        if (!in_array($this->container['priority'], $allowed_values)) {
            return false;
        }
        return true;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets status
     * @param string $status
     * @return $this
     */
    public function setStatus($status)
    {
        $allowed_values = array('INITIAL', 'DELEGATED', 'STARTED', 'CANCELLED', 'FINISHED', 'COMPLETE', 'PAUSED');
        if (!in_array($status, $allowed_values)) {
            throw new \InvalidArgumentException("Invalid value for 'status', must be one of 'INITIAL', 'DELEGATED', 'STARTED', 'CANCELLED', 'FINISHED', 'COMPLETE', 'PAUSED'");
        }
        $this->container['status'] = $status;

        return $this;
    }

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

    /**
     * Sets priority
     * @param string $priority
     * @return $this
     */
    public function setPriority($priority)
    {
        $allowed_values = array('1', '2', '3', '4', '5');
        if (!in_array($priority, $allowed_values)) {
            throw new \InvalidArgumentException("Invalid value for 'priority', must be one of '1', '2', '3', '4', '5'");
        }
        $this->container['priority'] = $priority;

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Gets instance_overdue_percentage
     * @return double
     */
    public function getInstanceOverduePercentage()
    {
        return $this->container['instance_overdue_percentage'];
    }

    /**
     * Sets instance_overdue_percentage
     * @param double $instance_overdue_percentage
     * @return $this
     */
    public function setInstanceOverduePercentage($instance_overdue_percentage)
    {
        $this->container['instance_overdue_percentage'] = $instance_overdue_percentage;

        return $this;
    }

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

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

        return $this;
    }

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

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

        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\Providers;

use Nur\Kernel\ServiceProvider;
use Illuminate\View\FileViewFinder;
use Illuminate\View\Factory;
use Illuminate\View\Engines\PhpEngine;
use Illuminate\View\Engines\FileEngine;
use Illuminate\View\Engines\CompilerEngine;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\Compilers\BladeCompiler;

class Blade extends ServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     * @throws
     */
    public function register()
    {
        $this->registerFactory();
        $this->registerViewFinder();
        $this->registerEngineResolver();
        $this->registerBladeEngine($this->app['view.engine.resolver']);
        $this->registerDirectives($this->app['blade.compiler']);
    }

    /**
     * Register the view environment.
     *
     * @return mixed
     */
    public function registerFactory()
    {
        $this->app->singleton('view', function ($app) {
            // Next we need to grab the engine resolver instance that will be used by the
            // environment. The resolver will be used by an environment to get each of
            // the various engine implementations such as plain PHP or Blade engine.
            $resolver = $app['view.engine.resolver'];
            $finder = $app['view.finder'];
            $env = new Factory($resolver, $finder, $app['events']);
            // We will also set the container instance on this view environment since the
            // view composers may be classes registered in the container, which allows
            // for great testable, flexible composers for the application developer.
            $env->setContainer($app);
            $env->share('app', $app);
            return $env;
        });
    }

    /**
     * Register the view finder implementation.
     *
     * @return void
     */
    public function registerViewFinder()
    {
        $this->app->singleton('view.finder', function ($app) {
            return new FileViewFinder($app['files'], [app_path('Views')]);
        });
    }

    /**
     * Register the engine resolver instance.
     *
     * @return void
     */
    public function registerEngineResolver()
    {
        $this->app->singleton('view.engine.resolver', function ($app) {
            $resolver = new EngineResolver;
            // Next we will register the various engines with the resolver so that the
            // environment can resolve the engines it needs for various views based
            // on the extension of view files. We call a method for each engines.
            foreach (['file', 'php', 'blade'] as $engine) {
                $this->{'register' . ucfirst($engine) . 'Engine'}($resolver);
            }
            return $resolver;
        });
    }

    /**
     * Register the file engine implementation.
     *
     * @param  \Illuminate\View\Engines\EngineResolver $resolver
     *
     * @return void
     */
    public function registerFileEngine($resolver)
    {
        $resolver->register('file', function () {
            return new FileEngine;
        });
    }

    /**
     * Register the PHP engine implementation.
     *
     * @param  \Illuminate\View\Engines\EngineResolver $resolver
     *
     * @return void
     */
    public function registerPhpEngine($resolver)
    {
        $resolver->register('php', function () {
            return new PhpEngine;
        });
    }

    /**
     * Register the Blade engine implementation.
     *
     * @param  \Illuminate\View\Engines\EngineResolver $resolver
     *
     * @return void
     */
    public function registerBladeEngine($resolver)
    {
        // The Compiler engine requires an instance of the CompilerInterface, which in
        // this case will be the Blade compiler, so we'll first create the compiler
        // instance to pass into the engine so it can compile the views properly.
        $this->app->singleton('blade.compiler', function ($app) {
            return new BladeCompiler($app['files'], realpath(cache_path('blade')));
        });

        $resolver->register('blade', function () {
            return new CompilerEngine($this->app['blade.compiler']);
        });
    }

    /**
     * Add extra directives to the blade templating compiler.
     *
     * @param BladeCompiler $blade The compiler to extend
     *
     * @return void
     */
    public function registerDirectives(BladeCompiler $blade)
    {
        $keywords = [
            "namespace",
            "use",
        ];

        foreach ($keywords as $keyword) {
            $blade->directive($keyword, function ($parameter) use ($keyword) {
                $parameter = trim($parameter, "()");
                return "<?php {$keyword} {$parameter} ?>";
            });
        }

        $assetify = function ($file, $type) {
            $file = trim($file, "()");
            if (in_array(substr($file, 0, 1), ["'", '"'], true)) {
                $file = trim($file, "'\"");
            } else {
                return "{{ {$file} }}";
            }
            if (substr($file, 0, 1) !== "/") {
                $file = "/{$type}/{$file}";
            }
            if (substr($file, (strlen($type) + 1) * -1) !== ".{$type}") {
                $file .= ".{$type}";
            }
            return $file;
        };

        $blade->directive("css", function ($parameter) use ($assetify) {
            $file = $assetify($parameter, "css");
            return '<link rel="stylesheet" type="text/css" href="' . $file . '"/>';
        });

        $blade->directive("js", function ($parameter) use ($assetify) {
            $file = $assetify($parameter, "js");
            return '<script type="text/javascript" src="' . $file . '"></script>';
        });
    }
}


<?php

namespace Nur\Hash;

use RuntimeException;

class ArgonHash extends AbstractHash implements HashInterface
{
    /**
     * The default memory cost factor.
     *
     * @var int
     */
    protected $memory = 1024;

    /**
     * The default time cost factor.
     *
     * @var int
     */
    protected $time = 2;

    /**
     * The default threads factor.
     *
     * @var int
     */
    protected $threads = 2;

    /**
     * Create a new hasher instance.
     *
     * @param  array $options
     *
     * @return void
     */
    public function __construct(array $options = [])
    {
        $this->time = $options['time'] ?? $this->time;
        $this->memory = $options['memory'] ?? $this->memory;
        $this->threads = $options['threads'] ?? $this->threads;
    }

    /**
     * Hash the given value.
     *
     * @param  string $value
     * @param  array  $options
     *
     * @return string
     */
    public function make($value, array $options = [])
    {
        $hash = password_hash($value, PASSWORD_ARGON2I, [
            'memory_cost' => $this->memory($options),
            'time_cost' => $this->time($options),
            'threads' => $this->threads($options),
        ]);

        if ($hash === false) {
            throw new RuntimeException('Argon2 hashing not supported.');
        }

        return $hash;
    }

    /**
     * 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 password_needs_rehash($hashedValue, PASSWORD_ARGON2I, [
            'memory_cost' => $this->memory($options),
            'time_cost' => $this->time($options),
            'threads' => $this->threads($options),
        ]);
    }

    /**
     * Set the default password memory factor.
     *
     * @param  int $memory
     *
     * @return $this
     */
    public function setMemory(int $memory)
    {
        $this->memory = $memory;

        return $this;
    }

    /**
     * Set the default password timing factor.
     *
     * @param  int $time
     *
     * @return $this
     */
    public function setTime(int $time)
    {
        $this->time = $time;

        return $this;
    }

    /**
     * Set the default password threads factor.
     *
     * @param  int $threads
     *
     * @return $this
     */
    public function setThreads(int $threads)
    {
        $this->threads = $threads;

        return $this;
    }

    /**
     * Extract the memory cost value from the options array.
     *
     * @param  array $options
     *
     * @return int
     */
    protected function memory(array $options)
    {
        return $options['memory'] ?? $this->memory;
    }

    /**
     * Extract the time cost value from the options array.
     *
     * @param  array $options
     *
     * @return int
     */
    protected function time(array $options)
    {
        return $options['time'] ?? $this->time;
    }

    /**
     * Extract the threads value from the options array.
     *
     * @param  array $options
     *
     * @return int
     */
    protected function threads(array $options)
    {
        return $options['threads'] ?? $this->threads;
    }
}


<?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 RemoveCommand extends AbstractCommand
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        parent::configure();

        $this->setName('remove')
             ->addArgument('version', InputArgument::REQUIRED, 'The version number for the migration')
             ->setDescription('Remove a specific migration')
             ->setHelp(<<<EOT
The <info>up</info> command removes a specific migration

EOT
        );
    }

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

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

        $version = $input->getArgument('version');

        if (in_array($version, $versions)) {
            $output->writeLn('<error>-Error!</error> "'.$version.'" migration is active. Please down it first.');
            return;
        }

        if (!isset($migrations[$version])) {
            $output->writeLn('<error>-Error!</error> "'.$version.'" migration not found. Please check migration ID.');
            return;
        }

        $mask = glob(database_path('migrations/'.$version.'_*.php'));
        array_map('unlink', $mask);
        $output->writeLn('<info>+Success!</info> "'.$version.'" migration removed.');
    }
}