# Temporary

trait Temporary

## Methods

`public` | `` | `generateHash($origin)` | No description |
`public` | `` | `hour()` | No description |
`public` | `` | `storageTemp()` | No description |
`public` | `` | `loadTemp()` | No description |
`public` | `` | `clearRouteTemp($route)` | No description |
`public` | `` | `gen($hash, $origin, $time, $method, $minutes)` | No description |

## Details

at line 9

### `generateHash()`

`public generateHash($origin)`

#### Parameters

| `$origin` |

at line 13

### `hour()`

`public hour()`
at line 17

### `storageTemp()`

`public storageTemp()`
at line 25

### `loadTemp()`

`public loadTemp()`
at line 31

### `clearRouteTemp()`

`public clearRouteTemp($route)`

#### Parameters

| `$route` |

at line 43

### `gen()`

`public gen($hash, $origin, $time, $method, $minutes)`

#### Parameters

| `$hash` |
| `$origin` |
| `$time` |
| `$method` |
| `$minutes` |

## Source code

    <?php

    	namespace App\Khan\Component\Router\Router;
    	use App\Khan\Component\Hooks\Hooks as Hooks;
    	date_default_timezone_set('America/Sao_Paulo');

    	trait Temporary {

    		public function generateHash($origin){
    			return md5($origin.mt_rand(0, 100000));
    		}

    		public function hour(){
    			return new \DateTime();
    		}

    		public function storageTemp(){
    			if(!Hooks::exists('storage/temp') && !Hooks::exists('storage/temp/temp.json')){
    				Hooks::folder(__DIR__. '/storage');
    				Hooks::folder(__DIR__. '/storage/temp');
    				Hooks::create(__DIR__. '/storage/temp/temp.json', json_encode([]));
    			}
    		}

    		public function loadTemp(){
    			return (array) json_decode(
    				Hooks::read(__DIR__. '/storage/temp/temp.json')
    			);
    		}

    		public function clearRouteTemp($route){
    			$temp = $this->loadTemp();
    			if(isset($temp[$route])){
    				unset($temp[$route]);
    				if(!isset($temp[$route])){
    					return Hooks::write(__DIR__. '/storage/temp/temp.json',
    						json_encode($temp)
    					);
    				}
    			}
    		}

    		public function gen($hash, $origin, $time, $method, $minutes){
    			$this->storageTemp();
    			$temp = $this->loadTemp();
    			if(!isset($temp[$hash])){
    				$temp[$hash] = [
    					"origin" => $origin,
    					"time" => $time,
    					"method" => $method,
    					"minutes" => $minutes
    				];

    				if(Hooks::write(__DIR__. '/storage/temp/temp.json',
    				json_encode($temp))){
    					return $_ENV['APP_URL'].$hash;
    				}

    			}
    		}

    	}