Completed
Push — master ( 1459ee...4560a8 )
by David
03:37
created
app/Console/Commands/CallRoute.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -10,29 +10,29 @@
 block discarded – undo
10 10
 
11 11
 class CallRoute extends Command {
12 12
 
13
-    protected $name = 'route:call';
14
-    protected $description = 'Call route from CLI';
15
-
16
-    public function __construct()
17
-    {
18
-        parent::__construct();
19
-    }
20
-
21
-    public function fire()
22
-    {
23
-        $request = Request::create((string)$this->option('uri'), 'GET');
24
-        $request->headers->set('X-Authorization', $this->option('token'));
25
-        $this->info(strip_tags(
26
-        	app()['Illuminate\Contracts\Http\Kernel']->handle($request)
27
-        ));
28
-    }
29
-
30
-    protected function getOptions()
31
-    {
32
-        return [
33
-            ['token', null, InputOption::VALUE_REQUIRED, 'The auth token', null],
34
-            ['uri', null, InputOption::VALUE_REQUIRED, 'The path of the route to be called', null],
35
-        ];
36
-    }
13
+	protected $name = 'route:call';
14
+	protected $description = 'Call route from CLI';
15
+
16
+	public function __construct()
17
+	{
18
+		parent::__construct();
19
+	}
20
+
21
+	public function fire()
22
+	{
23
+		$request = Request::create((string)$this->option('uri'), 'GET');
24
+		$request->headers->set('X-Authorization', $this->option('token'));
25
+		$this->info(strip_tags(
26
+			app()['Illuminate\Contracts\Http\Kernel']->handle($request)
27
+		));
28
+	}
29
+
30
+	protected function getOptions()
31
+	{
32
+		return [
33
+			['token', null, InputOption::VALUE_REQUIRED, 'The auth token', null],
34
+			['uri', null, InputOption::VALUE_REQUIRED, 'The path of the route to be called', null],
35
+		];
36
+	}
37 37
 
38 38
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
 
21 21
     public function fire()
22 22
     {
23
-        $request = Request::create((string)$this->option('uri'), 'GET');
23
+        $request = Request::create((string) $this->option('uri'), 'GET');
24 24
         $request->headers->set('X-Authorization', $this->option('token'));
25 25
         $this->info(strip_tags(
26 26
         	app()['Illuminate\Contracts\Http\Kernel']->handle($request)
Please login to merge, or discard this patch.
app/Library/Sftp.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -7,154 +7,154 @@
 block discarded – undo
7 7
 class Sftp
8 8
 {
9 9
     
10
-    protected $connectionName;
11
-
12
-    /**
13
-     * Constructor
14
-     *
15
-     * @param string $connectionName
16
-     */
17
-    public function __construct($connectionName)
18
-    {
19
-        $this->connectionName = $connectionName;
20
-    }
21
-
22
-    /**
23
-     * Gets all XML files from a remote folder
24
-     * 
25
-     * @param  string $remoteDir 
26
-     * @param  string $localDir 
27
-     * @return array
28
-     */
10
+	protected $connectionName;
11
+
12
+	/**
13
+	 * Constructor
14
+	 *
15
+	 * @param string $connectionName
16
+	 */
17
+	public function __construct($connectionName)
18
+	{
19
+		$this->connectionName = $connectionName;
20
+	}
21
+
22
+	/**
23
+	 * Gets all XML files from a remote folder
24
+	 * 
25
+	 * @param  string $remoteDir 
26
+	 * @param  string $localDir 
27
+	 * @return array
28
+	 */
29 29
    	public function getFiles($remoteDir, $localDir)
30 30
    	{    	
31
-    	$files = $this->remoteListPackaged($remoteDir);
31
+		$files = $this->remoteListPackaged($remoteDir);
32 32
 
33
-    	foreach ($files as $file) {			
33
+		foreach ($files as $file) {			
34 34
 			$this->getFile($file['fullFileName'], $localDir . '/' . $file['fileName']);
35 35
 		}
36 36
 
37
-    	return $files;
37
+		return $files;
38 38
   	}
39 39
 
40
-    /**
41
-     * Gets all XML files from a remote folder
42
-     * 
43
-     * @param  string 	$dir 
44
-     * @param  bool     $sorted 
45
-     * @param  string   $sortOrder 
46
-     * @return array
47
-     */
40
+	/**
41
+	 * Gets all XML files from a remote folder
42
+	 * 
43
+	 * @param  string 	$dir 
44
+	 * @param  bool     $sorted 
45
+	 * @param  string   $sortOrder 
46
+	 * @return array
47
+	 */
48 48
    	public function remoteListPackaged($dir, $sorted = true, $sortOrder = 'desc')
49 49
    	{    	
50
-    	$files = [];
50
+		$files = [];
51 51
 		$all = $this->remoteList($dir, $sorted, $sortOrder);
52 52
 		
53
-        foreach ($all as $file=>$val) {
53
+		foreach ($all as $file=>$val) {
54 54
 			if ($this->isValidExtension($val['filename'])) {
55 55
 				$files[] = [
56
-                    'fileName' => $val['filename'], 
57
-                    'fullFileName' => $dir . '/' .$val['filename'],
58
-                    'size' => $val['size'],
59
-                    'modified' => gmdate("m/d/Y H:i:s", $val['mtime']),
60
-                ];
56
+					'fileName' => $val['filename'], 
57
+					'fullFileName' => $dir . '/' .$val['filename'],
58
+					'size' => $val['size'],
59
+					'modified' => gmdate("m/d/Y H:i:s", $val['mtime']),
60
+				];
61 61
 			}
62 62
 		}
63 63
 
64 64
 		return $files;
65
-    }
65
+	}
66 66
 
67
-    /**
68
-     * Retrieves a file from a SSH/SFTP server
69
-     * 
70
-     * @param  string $remoteFile 
71
-     * @param  string $localFile 
67
+	/**
68
+	 * Retrieves a file from a SSH/SFTP server
69
+	 * 
70
+	 * @param  string $remoteFile 
71
+	 * @param  string $localFile 
72 72
 	 * @return \Symfony\Component\Console\Output\OutputInterface
73
-     */
74
-    public function getFile($remoteFile, $localFile)
75
-    {	
76
-    	return \SSH::into($this->connectionName)->get($remoteFile, $localFile);    
77
-    }
78
-
79
-    /**
80
-     * Places a file on a remote SSH/SFTP server
81
-     * 
82
-     * @param  string $remoteFile 
83
-     * @param  string $localFile 
73
+	 */
74
+	public function getFile($remoteFile, $localFile)
75
+	{	
76
+		return \SSH::into($this->connectionName)->get($remoteFile, $localFile);    
77
+	}
78
+
79
+	/**
80
+	 * Places a file on a remote SSH/SFTP server
81
+	 * 
82
+	 * @param  string $remoteFile 
83
+	 * @param  string $localFile 
84 84
 	 * @return \Symfony\Component\Console\Output\OutputInterface
85
-     */
86
-    public function putFile($remoteFile, $localFile)
87
-    {
88
-    	return \SSH::into($this->connectionName)->put($localFile, $remoteFile);
89
-    }
90
-
91
-    /**
92
-     * Retrieves a listing from directory
93
-     * 
94
-     * @param  string 	$dir 
95
-     * @param  bool     $sorted 
96
-     * @param  string   $sortOrder 
85
+	 */
86
+	public function putFile($remoteFile, $localFile)
87
+	{
88
+		return \SSH::into($this->connectionName)->put($localFile, $remoteFile);
89
+	}
90
+
91
+	/**
92
+	 * Retrieves a listing from directory
93
+	 * 
94
+	 * @param  string 	$dir 
95
+	 * @param  bool     $sorted 
96
+	 * @param  string   $sortOrder 
97 97
 	 * @return array 	array of files and folders	
98
-     */
99
-    public function remoteList($dir, $sorted = true, $sortOrder = 'desc')
100
-    {
101
-    	$conn = $this->getConnection();
102
-    	$conn->chdir($dir);
103
-        $list = $conn->rawlist();
104
-
105
-        if ($sorted) {
106
-            $list = $this->sortList($list, $sortOrder);
107
-        }
98
+	 */
99
+	public function remoteList($dir, $sorted = true, $sortOrder = 'desc')
100
+	{
101
+		$conn = $this->getConnection();
102
+		$conn->chdir($dir);
103
+		$list = $conn->rawlist();
104
+
105
+		if ($sorted) {
106
+			$list = $this->sortList($list, $sortOrder);
107
+		}
108 108
     	
109
-    	return $list;    
110
-    }
111
-
112
-    /**
113
-     * Retrieves a listing from directory
114
-     * 
115
-     * @param  array    $list 
116
-     * @param  string   $sortOrder 
117
-     * @return array    sorted array of a folder
118
-     */
119
-    public function sortList($list, $sortOrder = 'desc')
120
-    {
121
-        usort($list, function($a, $b) { return $a['mtime'] - $b['mtime']; }); 
122
-
123
-        return $sortOrder == 'asc' ? $list : array_reverse($list);
124
-    }
125
-
126
-    /**
127
-     * Retrieves a listing from directory
128
-     * 
129
-     * @param  string   $remoteFileFrom 
130
-     * @param  string   $remoteFileTo 
131
-     * @return boolean  success
132
-     */
133
-    public function rename($remoteFileFrom, $remoteFileTo)
134
-    {
135
-        $conn = $this->getConnection();
136
-        //print $conn->getSFTPLog();
137
-        return $conn->rename($remoteFileFrom, $remoteFileTo);
138
-    }
139
-
140
-    /**
141
-     * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality
142
-     * 
143
-     * @return Net_SFTP connection
144
-     */
145
-    protected function getConnection()
146
-    {
147
-    	return \SSH::into($this->connectionName)->getGateway()->getConnection();
148
-    }
149
-
150
-    /**
151
-     * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality
152
-     * 
153
-     * @param  string $fileName 
154
-     * @return bool 	
155
-     */
156
-    protected function isValidExtension($fileName)
157
-    {
158
-    	return substr(strrchr($fileName,'.'),1) === 'xml' || substr(strrchr($fileName,'.'),1) === 'err';
159
-    }
109
+		return $list;    
110
+	}
111
+
112
+	/**
113
+	 * Retrieves a listing from directory
114
+	 * 
115
+	 * @param  array    $list 
116
+	 * @param  string   $sortOrder 
117
+	 * @return array    sorted array of a folder
118
+	 */
119
+	public function sortList($list, $sortOrder = 'desc')
120
+	{
121
+		usort($list, function($a, $b) { return $a['mtime'] - $b['mtime']; }); 
122
+
123
+		return $sortOrder == 'asc' ? $list : array_reverse($list);
124
+	}
125
+
126
+	/**
127
+	 * Retrieves a listing from directory
128
+	 * 
129
+	 * @param  string   $remoteFileFrom 
130
+	 * @param  string   $remoteFileTo 
131
+	 * @return boolean  success
132
+	 */
133
+	public function rename($remoteFileFrom, $remoteFileTo)
134
+	{
135
+		$conn = $this->getConnection();
136
+		//print $conn->getSFTPLog();
137
+		return $conn->rename($remoteFileFrom, $remoteFileTo);
138
+	}
139
+
140
+	/**
141
+	 * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality
142
+	 * 
143
+	 * @return Net_SFTP connection
144
+	 */
145
+	protected function getConnection()
146
+	{
147
+		return \SSH::into($this->connectionName)->getGateway()->getConnection();
148
+	}
149
+
150
+	/**
151
+	 * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality
152
+	 * 
153
+	 * @param  string $fileName 
154
+	 * @return bool 	
155
+	 */
156
+	protected function isValidExtension($fileName)
157
+	{
158
+		return substr(strrchr($fileName,'.'),1) === 'xml' || substr(strrchr($fileName,'.'),1) === 'err';
159
+	}
160 160
 }
161 161
\ No newline at end of file
Please login to merge, or discard this patch.
app/LaravelRestCms/BaseModel.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -28,43 +28,43 @@  discard block
 block discarded – undo
28 28
 	/**
29 29
 	 * The plural version of the table name
30 30
 	 * 
31
-	* @var string
31
+	 * @var string
32 32
 	 */
33 33
 	protected $plural;
34 34
 
35 35
 	/**
36 36
 	 * The Validator object
37 37
 	 * 
38
-	* @var \Validator
38
+	 * @var \Validator
39 39
 	 */
40 40
 	protected $validation;
41 41
 
42 42
 	/**
43 43
 	 * Rules to validate when creating a model
44 44
 	 * 
45
-	* @var array
45
+	 * @var array
46 46
 	 */
47 47
 	protected static $createRules;
48 48
 
49 49
 	/**
50 50
 	 * Rules to validate when updating a model
51 51
 	 * 
52
-	* @var array
52
+	 * @var array
53 53
 	 */
54 54
 	protected static $updateRules;
55 55
 
56 56
 	/**
57
-     * The "booting" method of the model.
58
-     *
59
-     * @return void
60
-     */
61
-    protected static function boot()
62
-    {
63
-        parent::boot();
64
-
65
-        static::savedEvent();
66
-        static::deletingEvent();
67
-    }	 
57
+	 * The "booting" method of the model.
58
+	 *
59
+	 * @return void
60
+	 */
61
+	protected static function boot()
62
+	{
63
+		parent::boot();
64
+
65
+		static::savedEvent();
66
+		static::deletingEvent();
67
+	}	 
68 68
 	
69 69
 	/**
70 70
 	 * Gets the table name of the model.
@@ -77,35 +77,35 @@  discard block
 block discarded – undo
77 77
 		return $this->table;
78 78
 	}
79 79
 
80
-    /**
81
-     * Hooks into the "saved" event
82
-     * 
83
-     * @return void
84
-     */
85
-    protected static function savedEvent()
86
-    {
87
-        static::saved(function($model)
88
-        {
89
-            static::addToCache($model);
90
-
91
-            return true;
92
-        });
93
-    }
94
-
95
-    /**
96
-     * Hooks into the "deleting" event
97
-     * 
98
-     * @return void
99
-     */
100
-    protected static function deletingEvent()
101
-    {
102
-        static::deleting(function($model)
103
-        {
104
-           static::removeFromCache($model);
105
-
106
-            return true;
107
-        });
108
-    }
80
+	/**
81
+	 * Hooks into the "saved" event
82
+	 * 
83
+	 * @return void
84
+	 */
85
+	protected static function savedEvent()
86
+	{
87
+		static::saved(function($model)
88
+		{
89
+			static::addToCache($model);
90
+
91
+			return true;
92
+		});
93
+	}
94
+
95
+	/**
96
+	 * Hooks into the "deleting" event
97
+	 * 
98
+	 * @return void
99
+	 */
100
+	protected static function deletingEvent()
101
+	{
102
+		static::deleting(function($model)
103
+		{
104
+		   static::removeFromCache($model);
105
+
106
+			return true;
107
+		});
108
+	}
109 109
 	
110 110
 	/**
111 111
 	 * Retrieves the singular name of the table
Please login to merge, or discard this patch.
app/LaravelRestCms/ApiKey/ApiKeyTransformer.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -5,17 +5,17 @@
 block discarded – undo
5 5
 
6 6
 class ApiKeyTransformer extends TransformerAbstract {
7 7
 
8
-    /**
9
-     * Perform transformations on the data
10
-     * 
11
-     * @param  ApiKey $apiKey Eloquent collection
12
-     * @return array
13
-     */
14
-    public function transform(ApiGuardApiKey $apiKey)
15
-    {
16
-        return [
17
-            'key'   => $apiKey->key,
18
-            'level' => $apiKey->level,
19
-        ];
20
-    }
8
+	/**
9
+	 * Perform transformations on the data
10
+	 * 
11
+	 * @param  ApiKey $apiKey Eloquent collection
12
+	 * @return array
13
+	 */
14
+	public function transform(ApiGuardApiKey $apiKey)
15
+	{
16
+		return [
17
+			'key'   => $apiKey->key,
18
+			'level' => $apiKey->level,
19
+		];
20
+	}
21 21
 }
22 22
\ No newline at end of file
Please login to merge, or discard this patch.
app/LaravelRestCms/SearchTrait.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -2,81 +2,81 @@
 block discarded – undo
2 2
 
3 3
 trait SearchTrait {
4 4
 
5
-    public static $labelCol = [];
6
-    public static $searchCols = [];
5
+	public static $labelCol = [];
6
+	public static $searchCols = [];
7 7
 
8
-    /**
9
-     * Adds search methods to the model
10
-     *         
11
-     * @param string $keyword
12
-     * @param string $labelCol
13
-     * @return \BaseModel
14
-     */
15
-    public function addSearch($keyword = null, $labelCol = null)
16
-    {
17
-        $searchCols = self::getSearchCols(null, $labelCol);
18
-        $keyword = strtolower($keyword);
8
+	/**
9
+	 * Adds search methods to the model
10
+	 *         
11
+	 * @param string $keyword
12
+	 * @param string $labelCol
13
+	 * @return \BaseModel
14
+	 */
15
+	public function addSearch($keyword = null, $labelCol = null)
16
+	{
17
+		$searchCols = self::getSearchCols(null, $labelCol);
18
+		$keyword = strtolower($keyword);
19 19
         
20
-        if ($searchCols && !is_null($keyword) && trim($keyword) != '') {
20
+		if ($searchCols && !is_null($keyword) && trim($keyword) != '') {
21 21
             
22
-            return self::orWhere(function($query) use ($searchCols, $keyword)
23
-            {
24
-                foreach ($searchCols as $key=>$val) {
25
-                    $query->orWhere($val, 'like', "%{$keyword}%");
26
-                }
27
-            });
28
-        } else {
29
-            return $this;
30
-        }
31
-    }
22
+			return self::orWhere(function($query) use ($searchCols, $keyword)
23
+			{
24
+				foreach ($searchCols as $key=>$val) {
25
+					$query->orWhere($val, 'like', "%{$keyword}%");
26
+				}
27
+			});
28
+		} else {
29
+			return $this;
30
+		}
31
+	}
32 32
     
33
-    /**
34
-     * Retrieves the columns to search
35
-     * 
36
-     * @param  string $override
37
-     * @param  string $default
38
-     * @return array
39
-     */
40
-    public function getSearchCols($override = null, $default = null)
41
-    {
42
-        if (!is_null($override)) {
43
-            $searchCols = $override;
44
-        } else if (!is_null(static::$searchCols)) {
45
-            $searchCols = static::$searchCols;
46
-        } else if (!is_null(static::$labelCol)) {
47
-            $searchCols = static::$labelCol;
48
-        } else if (!is_null($default)) {
49
-            $searchCols = $default;
50
-        } else {
51
-            return false;
52
-        }
33
+	/**
34
+	 * Retrieves the columns to search
35
+	 * 
36
+	 * @param  string $override
37
+	 * @param  string $default
38
+	 * @return array
39
+	 */
40
+	public function getSearchCols($override = null, $default = null)
41
+	{
42
+		if (!is_null($override)) {
43
+			$searchCols = $override;
44
+		} else if (!is_null(static::$searchCols)) {
45
+			$searchCols = static::$searchCols;
46
+		} else if (!is_null(static::$labelCol)) {
47
+			$searchCols = static::$labelCol;
48
+		} else if (!is_null($default)) {
49
+			$searchCols = $default;
50
+		} else {
51
+			return false;
52
+		}
53 53
         
54
-        return (array) $searchCols;
55
-    }
54
+		return (array) $searchCols;
55
+	}
56 56
     
57
-    /**
58
-     * Eloquent scope of the search
59
-     * 
60
-     * @param  Illuminate\Database\Eloquent\Builder $query
61
-     * @param  string $keyword
62
-     * @return Illuminate\Database\Eloquent\Builder
63
-     */
64
-    public function scopeSearch($query, $keyword = null) 
65
-    {        
66
-        $searchCols = $this->getSearchCols(null, static::$labelCol);
67
-        $query->select('*', implode(' ', static::$labelCol) .  ' as label', 'url');
68
-        $match = '';
57
+	/**
58
+	 * Eloquent scope of the search
59
+	 * 
60
+	 * @param  Illuminate\Database\Eloquent\Builder $query
61
+	 * @param  string $keyword
62
+	 * @return Illuminate\Database\Eloquent\Builder
63
+	 */
64
+	public function scopeSearch($query, $keyword = null) 
65
+	{        
66
+		$searchCols = $this->getSearchCols(null, static::$labelCol);
67
+		$query->select('*', implode(' ', static::$labelCol) .  ' as label', 'url');
68
+		$match = '';
69 69
 
70
-        // make search results use the "and" clause
71
-        $keyword[0] = '"' . $keyword[0] . '"';
70
+		// make search results use the "and" clause
71
+		$keyword[0] = '"' . $keyword[0] . '"';
72 72
 
73
-        if (is_array($searchCols)) {
74
-            foreach ($searchCols as $searchCol) {
75
-                $match = "MATCH(" . $searchCol . ") AGAINST (? IN BOOLEAN MODE)";
76
-                $query = $query->whereRaw($match, $keyword);
77
-            }
78
-        }
73
+		if (is_array($searchCols)) {
74
+			foreach ($searchCols as $searchCol) {
75
+				$match = "MATCH(" . $searchCol . ") AGAINST (? IN BOOLEAN MODE)";
76
+				$query = $query->whereRaw($match, $keyword);
77
+			}
78
+		}
79 79
                
80
-        return $query->orderByRaw($match . ' desc', $keyword);  
81
-    }
80
+		return $query->orderByRaw($match . ' desc', $keyword);  
81
+	}
82 82
 }
83 83
\ No newline at end of file
Please login to merge, or discard this patch.
app/LaravelRestCms/User/UserTransformer.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -4,28 +4,28 @@
 block discarded – undo
4 4
 
5 5
 class UserTransformer extends TransformerAbstract {
6 6
 
7
-    /**
8
-     * List of resources possible to include
9
-     *
10
-     * @var array
11
-     */
12
-    protected $availableIncludes = [
13
-    ];
7
+	/**
8
+	 * List of resources possible to include
9
+	 *
10
+	 * @var array
11
+	 */
12
+	protected $availableIncludes = [
13
+	];
14 14
 
15
-    /**
16
-     * Transforms a User model
17
-     * 
18
-     * @param  User $user
19
-     * @return array
20
-     */
21
-    public function transform(User $user)
22
-    {
23
-        return [
24
-            'id'     => (int) $user->id,
25
-            'first_name' => $user->first_name,
26
-            'last_name' => $user->last_name,
27
-            'api_key' => $user->apiKey->key,
28
-            'version' => \Config::get('laravel-rest-cms.version'),
29
-        ];
30
-    }
15
+	/**
16
+	 * Transforms a User model
17
+	 * 
18
+	 * @param  User $user
19
+	 * @return array
20
+	 */
21
+	public function transform(User $user)
22
+	{
23
+		return [
24
+			'id'     => (int) $user->id,
25
+			'first_name' => $user->first_name,
26
+			'last_name' => $user->last_name,
27
+			'api_key' => $user->apiKey->key,
28
+			'version' => \Config::get('laravel-rest-cms.version'),
29
+		];
30
+	}
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.
app/LaravelRestCms/CacheTrait.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -2,105 +2,105 @@
 block discarded – undo
2 2
 
3 3
 trait CacheTrait {
4 4
 
5
-    /**
6
-     * The key to use to cache this model
7
-     * @var string
8
-     */
9
-    public static $cacheKeyPart = 'id';
5
+	/**
6
+	 * The key to use to cache this model
7
+	 * @var string
8
+	 */
9
+	public static $cacheKeyPart = 'id';
10 10
     
11
-    /**
12
-     * The
13
-     * @var [type]
14
-     */
15
-    public static $cacheTime = '3600'; 
11
+	/**
12
+	 * The
13
+	 * @var [type]
14
+	 */
15
+	public static $cacheTime = '3600'; 
16 16
         
17 17
     
18
-    /**
19
-     * Tie caching features into the Eloquent::boot() method
20
-     */
21
-    public static function bootCacheTrait()
22
-    {
23
-        static::$cacheTime = \Config::get('laravel-rest-cms.cacheTime');
24
-    }
18
+	/**
19
+	 * Tie caching features into the Eloquent::boot() method
20
+	 */
21
+	public static function bootCacheTrait()
22
+	{
23
+		static::$cacheTime = \Config::get('laravel-rest-cms.cacheTime');
24
+	}
25 25
 
26
-    /**
27
-     * Adds a model to the cache
28
-     * 
29
-     * @param  string   $model      The name of the model
30
-     * @return void
31
-     */
32
-    protected static function addToCache($model)
33
-    {
34
-        $model::cache($model, $model->{$model::$cacheKeyPart}, $model::getModelCache($model));
35
-    }
26
+	/**
27
+	 * Adds a model to the cache
28
+	 * 
29
+	 * @param  string   $model      The name of the model
30
+	 * @return void
31
+	 */
32
+	protected static function addToCache($model)
33
+	{
34
+		$model::cache($model, $model->{$model::$cacheKeyPart}, $model::getModelCache($model));
35
+	}
36 36
 
37
-    /**
38
-     * Removes a model from the cache
39
-     * 
40
-     * @param  string   $model      The name of the model
41
-     * @return void
42
-     */
43
-    protected static function removeFromCache($model)
44
-    {
45
-        \Cache::forget($model::getCacheKey($model));
46
-    }
37
+	/**
38
+	 * Removes a model from the cache
39
+	 * 
40
+	 * @param  string   $model      The name of the model
41
+	 * @return void
42
+	 */
43
+	protected static function removeFromCache($model)
44
+	{
45
+		\Cache::forget($model::getCacheKey($model));
46
+	}
47 47
 
48
-    /**
49
-     * Retrieves the model
50
-     * Override this function to create a custom cache with eager loading
51
-     * 
52
-     * @param  string $model The name of the model
53
-     * @return string
54
-     */
55
-    public static function getModelCache($model)
56
-    {
57
-        return $model;
58
-    }       
48
+	/**
49
+	 * Retrieves the model
50
+	 * Override this function to create a custom cache with eager loading
51
+	 * 
52
+	 * @param  string $model The name of the model
53
+	 * @return string
54
+	 */
55
+	public static function getModelCache($model)
56
+	{
57
+		return $model;
58
+	}       
59 59
     
60
-    /**
61
-     * Caches a model
62
-     * 
63
-     * @param  string   $model      The name of the model
64
-     * @param  string   $keyPart    The key to use to cache the model (e.g. primary key)
65
-     * @param  App\LaravelRestCms\BaseModel $data   The model instance
66
-     * @return string
67
-     */
68
-    public static function cache($model, $keyPart, $data)
69
-    {
70
-        $key = static::getCacheKey($model, $keyPart);
71
-        \Cache::forget($key);
72
-        \Cache::put($key, $data, static::$cacheTime);
60
+	/**
61
+	 * Caches a model
62
+	 * 
63
+	 * @param  string   $model      The name of the model
64
+	 * @param  string   $keyPart    The key to use to cache the model (e.g. primary key)
65
+	 * @param  App\LaravelRestCms\BaseModel $data   The model instance
66
+	 * @return string
67
+	 */
68
+	public static function cache($model, $keyPart, $data)
69
+	{
70
+		$key = static::getCacheKey($model, $keyPart);
71
+		\Cache::forget($key);
72
+		\Cache::put($key, $data, static::$cacheTime);
73 73
         
74
-        return $model;
75
-    }       
74
+		return $model;
75
+	}       
76 76
     
77
-    /**
78
-     * Caches a model
79
-     * 
80
-     * @param  string   $model      The name of the model
81
-     * @param  string   $keyPart    The key to use to cache the model (e.g. primary key)
82
-     * @return string
83
-     */
84
-    public static function getCache($model, $keyPart)
85
-    {
86
-        $key = static::getCacheKey($model, $keyPart);
77
+	/**
78
+	 * Caches a model
79
+	 * 
80
+	 * @param  string   $model      The name of the model
81
+	 * @param  string   $keyPart    The key to use to cache the model (e.g. primary key)
82
+	 * @return string
83
+	 */
84
+	public static function getCache($model, $keyPart)
85
+	{
86
+		$key = static::getCacheKey($model, $keyPart);
87 87
         
88
-        return \Cache::get($key);
89
-    }
88
+		return \Cache::get($key);
89
+	}
90 90
     
91
-    /**
92
-     * Gets the cache key for a model
93
-     * 
94
-     * @param  string   $model      The name of the model
95
-     * @param  string   $keyPart    The key to use to cache the model (e.g. primary key)
96
-     * @return string
97
-     */
98
-    public static function getCacheKey($model, $keyPart = null)
99
-    {
100
-        if (is_null($keyPart)) {
101
-            $keyPart = static::$cacheKeyPart;
102
-        }
91
+	/**
92
+	 * Gets the cache key for a model
93
+	 * 
94
+	 * @param  string   $model      The name of the model
95
+	 * @param  string   $keyPart    The key to use to cache the model (e.g. primary key)
96
+	 * @return string
97
+	 */
98
+	public static function getCacheKey($model, $keyPart = null)
99
+	{
100
+		if (is_null($keyPart)) {
101
+			$keyPart = static::$cacheKeyPart;
102
+		}
103 103
         
104
-        return with(new $model)->getTable() . '.' . $keyPart;
105
-    }
104
+		return with(new $model)->getTable() . '.' . $keyPart;
105
+	}
106 106
 }
107 107
\ No newline at end of file
Please login to merge, or discard this patch.
app/Http/Controllers/API/V1/ApiController.php 1 patch
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -12,160 +12,160 @@
 block discarded – undo
12 12
 
13 13
 abstract class ApiController extends ApiGuardController
14 14
 {
15
-    /**
16
-     * Laraponse object, which abstracts Fractal
17
-     * 
18
-     * @var EllipseSynergie\ApiResponse\Laravel\Response
19
-     */
20
-    public $response;
15
+	/**
16
+	 * Laraponse object, which abstracts Fractal
17
+	 * 
18
+	 * @var EllipseSynergie\ApiResponse\Laravel\Response
19
+	 */
20
+	public $response;
21 21
     
22
-    /**
23
-     * The string name of the Eloquen Model
24
-     * 
25
-     * @var string
26
-     */
27
-    protected $modelName;
22
+	/**
23
+	 * The string name of the Eloquen Model
24
+	 * 
25
+	 * @var string
26
+	 */
27
+	protected $modelName;
28 28
     
29
-    /**
30
-     * The Eloquent Model
31
-     * 
32
-     * @var Illuminate\Database\Eloquent\Model
33
-     */
34
-    protected $model;
29
+	/**
30
+	 * The Eloquent Model
31
+	 * 
32
+	 * @var Illuminate\Database\Eloquent\Model
33
+	 */
34
+	protected $model;
35 35
     
36
-    /**
37
-     * The string name of the Transformer class
38
-     * 
39
-     * @var string
40
-     */
41
-    protected $transformerName;
36
+	/**
37
+	 * The string name of the Transformer class
38
+	 * 
39
+	 * @var string
40
+	 */
41
+	protected $transformerName;
42 42
     
43
-    /**
44
-     * The name of the collection that is returned in the JSON response
45
-     * 
46
-     * @var string
47
-     */
48
-    protected $collectionName;
43
+	/**
44
+	 * The name of the collection that is returned in the JSON response
45
+	 * 
46
+	 * @var string
47
+	 */
48
+	protected $collectionName;
49 49
     
50
-    /**
51
-     * The Fractal Manager
52
-     * 
53
-     * @var \League\Fractal\Manager
54
-     */
55
-    public $manager;
56
-
57
-
58
-    /**
59
-     * Constructor
60
-     */
61
-    public function __construct()
62
-    {
63
-        $this->response =  \Response::api();
50
+	/**
51
+	 * The Fractal Manager
52
+	 * 
53
+	 * @var \League\Fractal\Manager
54
+	 */
55
+	public $manager;
56
+
57
+
58
+	/**
59
+	 * Constructor
60
+	 */
61
+	public function __construct()
62
+	{
63
+		$this->response =  \Response::api();
64 64
         
65
-        if (!empty($this->modelName)) {
66
-            $this->model = new $this->modelName;
67
-        }
68
-
69
-        // if no collection name provided, use the model's table name
70
-        if (empty($this->collectionName)) {
71
-            $this->collectionName = $this->model->getTable();
72
-        }
65
+		if (!empty($this->modelName)) {
66
+			$this->model = new $this->modelName;
67
+		}
68
+
69
+		// if no collection name provided, use the model's table name
70
+		if (empty($this->collectionName)) {
71
+			$this->collectionName = $this->model->getTable();
72
+		}
73 73
         
74
-        // parse includes
75
-        if (\Input::get('include') != '') {
76
-            $this->manager = new \League\Fractal\Manager;
77
-            $this->manager->parseIncludes(explode(',', \Input::get('include')));
78
-        }
79
-
80
-        parent::__construct();
81
-    }
82
-
83
-    /**
84
-     * Create an item
85
-     * 
86
-     * @return \Illuminate\Http\JsonResponse
87
-     */
88
-    public function create($data = null)
89
-    {   
90
-        $data = $data ?: \Input::json()->all();
91
-
92
-        try {
93
-            $this->model->validate($data);
94
-            $item = $this->model->create($data);
74
+		// parse includes
75
+		if (\Input::get('include') != '') {
76
+			$this->manager = new \League\Fractal\Manager;
77
+			$this->manager->parseIncludes(explode(',', \Input::get('include')));
78
+		}
79
+
80
+		parent::__construct();
81
+	}
82
+
83
+	/**
84
+	 * Create an item
85
+	 * 
86
+	 * @return \Illuminate\Http\JsonResponse
87
+	 */
88
+	public function create($data = null)
89
+	{   
90
+		$data = $data ?: \Input::json()->all();
91
+
92
+		try {
93
+			$this->model->validate($data);
94
+			$item = $this->model->create($data);
95 95
             
96
-            return $this->showByObject($item);
96
+			return $this->showByObject($item);
97 97
         
98
-        } catch (ValidationException $e) {
99
-            return $this->response->setStatusCode(422)->withError($e->errors()->toArray(), 'GEN-UNPROCESSABLE-ENTITY');
100
-        }
101
-    }
102
-
103
-    /**
104
-     * Returns a single item
105
-     * 
106
-     * @param  int $id
107
-     * @return \Illuminate\Http\JsonResponse
108
-     */
109
-    public function show($id)
110
-    {        
111
-        try {
98
+		} catch (ValidationException $e) {
99
+			return $this->response->setStatusCode(422)->withError($e->errors()->toArray(), 'GEN-UNPROCESSABLE-ENTITY');
100
+		}
101
+	}
102
+
103
+	/**
104
+	 * Returns a single item
105
+	 * 
106
+	 * @param  int $id
107
+	 * @return \Illuminate\Http\JsonResponse
108
+	 */
109
+	public function show($id)
110
+	{        
111
+		try {
112 112
             
113
-            return $this->response->withItem($this->model->findOrFail($id), new $this->transformerName);
113
+			return $this->response->withItem($this->model->findOrFail($id), new $this->transformerName);
114 114
         
115
-        } catch (ModelNotFoundException $e) {
116
-
117
-            return $this->respondNotFound();
118
-        }
119
-    }
120
-
121
-    /**
122
-     * Returns a single item
123
-     * 
124
-     * @param  object $object
125
-     * @return \Illuminate\Http\JsonResponse
126
-     */
127
-    public function showByObject($object)
128
-    {        
129
-        try {
130
-            return $this->response->withItem($object, new $this->transformerName);
115
+		} catch (ModelNotFoundException $e) {
116
+
117
+			return $this->respondNotFound();
118
+		}
119
+	}
120
+
121
+	/**
122
+	 * Returns a single item
123
+	 * 
124
+	 * @param  object $object
125
+	 * @return \Illuminate\Http\JsonResponse
126
+	 */
127
+	public function showByObject($object)
128
+	{        
129
+		try {
130
+			return $this->response->withItem($object, new $this->transformerName);
131 131
         
132
-        } catch (ModelNotFoundException $e) {
133
-
134
-            return $this->respondNotFound();
135
-        }
136
-    }
137
-
138
-    /**
139
-     * Returns a paginated collection
140
-     * 
141
-     * @return \Illuminate\Http\JsonResponse
142
-     */
143
-    public function collection()
144
-    {
145
-        $limit = \Input::get('limit') ?: 10;
146
-        $model = $this->model;
132
+		} catch (ModelNotFoundException $e) {
133
+
134
+			return $this->respondNotFound();
135
+		}
136
+	}
137
+
138
+	/**
139
+	 * Returns a paginated collection
140
+	 * 
141
+	 * @return \Illuminate\Http\JsonResponse
142
+	 */
143
+	public function collection()
144
+	{
145
+		$limit = \Input::get('limit') ?: 10;
146
+		$model = $this->model;
147 147
         
148
-        if (\Request::has('order')) {
149
-            list($orderCol, $orderBy) = explode('|', \Input::get('order'));
150
-            $model = $model->orderBy($orderCol, $orderBy);
151
-        }
152
-
153
-        return $this->response->withPaginator($model->paginate($limit), new $this->transformerName, $this->collectionName);
154
-    }
155
-
156
-    /**
157
-     * Handles 404 errors
158
-     * 
159
-     * @param  string $msg
160
-     * @return \Illuminate\Http\JsonResponse
161
-     */
162
-    public function respondNotFound($msg = 'Not found!')
163
-    {
164
-        return \Response::json([
165
-            'error' => [
166
-                'message' => $msg,
167
-                'status_code' => 404
168
-            ]
169
-        ], 404);
170
-    }
148
+		if (\Request::has('order')) {
149
+			list($orderCol, $orderBy) = explode('|', \Input::get('order'));
150
+			$model = $model->orderBy($orderCol, $orderBy);
151
+		}
152
+
153
+		return $this->response->withPaginator($model->paginate($limit), new $this->transformerName, $this->collectionName);
154
+	}
155
+
156
+	/**
157
+	 * Handles 404 errors
158
+	 * 
159
+	 * @param  string $msg
160
+	 * @return \Illuminate\Http\JsonResponse
161
+	 */
162
+	public function respondNotFound($msg = 'Not found!')
163
+	{
164
+		return \Response::json([
165
+			'error' => [
166
+				'message' => $msg,
167
+				'status_code' => 404
168
+			]
169
+		], 404);
170
+	}
171 171
 }
172 172
\ No newline at end of file
Please login to merge, or discard this patch.
app/Http/Controllers/API/V1/UserController.php 1 patch
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -10,131 +10,131 @@
 block discarded – undo
10 10
 
11 11
 class UserController extends ApiGuardController
12 12
 {
13
-    /**
14
-     * The name of the model to use for this package
15
-     * 
16
-     * @var string
17
-     */
18
-    protected $modelName = 'App\LaravelRestCms\User\User';
13
+	/**
14
+	 * The name of the model to use for this package
15
+	 * 
16
+	 * @var string
17
+	 */
18
+	protected $modelName = 'App\LaravelRestCms\User\User';
19 19
     
20
-    /**
21
-     * The name of the transformer to use for this package
22
-     * 
23
-     * @var string
24
-     */
25
-    protected $transformerName = 'App\LaravelRestCms\User\UserTransformer';
20
+	/**
21
+	 * The name of the transformer to use for this package
22
+	 * 
23
+	 * @var string
24
+	 */
25
+	protected $transformerName = 'App\LaravelRestCms\User\UserTransformer';
26 26
     
27
-    /**
28
-     * The key to use as a key for this collection in the output
29
-     * 
30
-     * @var string
31
-     */
32
-    protected $collectionName = 'users';
33
-
34
-    /**
35
-     * The methods that don't require api authentication
36
-     * 
37
-     * @var array
38
-     */
39
-    protected $apiMethods = [
40
-        'authenticate' => [
41
-            'keyAuthentication' => false
42
-        ],
43
-        'deauthenticate' => [
44
-            'keyAuthentication' => false
45
-        ]
46
-    ];
47
-
48
-    /**
49
-     * Authenticate the login
50
-     * 
51
-     * @return \Illuminate\Http\JsonResponse|Illuminate\Contracts\Routing\ResponseFactory
52
-     */
53
-    public function authenticate() 
54
-    {
55
-        $credentials = [
56
-            'username' => Input::get('username'),
57
-            'password' => Input::get('password'),
58
-        ];
27
+	/**
28
+	 * The key to use as a key for this collection in the output
29
+	 * 
30
+	 * @var string
31
+	 */
32
+	protected $collectionName = 'users';
33
+
34
+	/**
35
+	 * The methods that don't require api authentication
36
+	 * 
37
+	 * @var array
38
+	 */
39
+	protected $apiMethods = [
40
+		'authenticate' => [
41
+			'keyAuthentication' => false
42
+		],
43
+		'deauthenticate' => [
44
+			'keyAuthentication' => false
45
+		]
46
+	];
47
+
48
+	/**
49
+	 * Authenticate the login
50
+	 * 
51
+	 * @return \Illuminate\Http\JsonResponse|Illuminate\Contracts\Routing\ResponseFactory
52
+	 */
53
+	public function authenticate() 
54
+	{
55
+		$credentials = [
56
+			'username' => Input::get('username'),
57
+			'password' => Input::get('password'),
58
+		];
59 59
         
60
-        $validator = Validator::make([
61
-                'username' => $credentials['username'],
62
-                'password' => $credentials['password']
63
-            ],
64
-            [
65
-                'username' => 'required|max:255',
66
-                'password' => 'required|max:255'
67
-            ]
68
-        );
60
+		$validator = Validator::make([
61
+				'username' => $credentials['username'],
62
+				'password' => $credentials['password']
63
+			],
64
+			[
65
+				'username' => 'required|max:255',
66
+				'password' => 'required|max:255'
67
+			]
68
+		);
69 69
         
70
-        if ($validator->fails()) {
71
-            return $this->response->errorWrongArgsValidator($validator);
72
-        }
73
-
74
-        try {
75
-            $user                 = with(new User)->authenticate($credentials['username'], $credentials['password'])->first();
76
-            $credentials['email'] = $user->email;
77
-        } catch (\ErrorException $e) {
78
-            return $this->response->errorUnauthorized("Your username or password is incorrect");
79
-        }
80
-
81
-        // We have validated this user
82
-        // Assign an API key for this session
83
-        $apiKey = ApiKey::where('user_id', '=', $user->id)->first();
70
+		if ($validator->fails()) {
71
+			return $this->response->errorWrongArgsValidator($validator);
72
+		}
73
+
74
+		try {
75
+			$user                 = with(new User)->authenticate($credentials['username'], $credentials['password'])->first();
76
+			$credentials['email'] = $user->email;
77
+		} catch (\ErrorException $e) {
78
+			return $this->response->errorUnauthorized("Your username or password is incorrect");
79
+		}
80
+
81
+		// We have validated this user
82
+		// Assign an API key for this session
83
+		$apiKey = ApiKey::where('user_id', '=', $user->id)->first();
84 84
         
85
-        if (!isset($apiKey)) {
86
-            $apiKey                = new ApiKey;
87
-            $apiKey->user_id       = $user->id;
88
-            $apiKey->key           = $apiKey->generateKey();
89
-            $apiKey->level         = 5;
90
-            $apiKey->ignore_limits = 0;
91
-        } else {
92
-            $apiKey->generateKey();
93
-        }
94
-
95
-        if (!$apiKey->save()) {
96
-            return $this->response->errorInternalError("Failed to create an API key. Please try again.");
97
-        }
98
-
99
-
100
-        // We have an API key.. i guess we only need to return that.
101
-        return $this->response->withItem($user, new \App\LaravelRestCms\User\UserTransformer);
102
-    }
103
-
104
-    /**
105
-     * Retrieve the user model
106
-     * 
107
-     * @return Model
108
-     */
109
-    public function getUserDetails() 
110
-    {
111
-        $user = $this->apiKey->user;
112
-
113
-        return isset($user) ? $user : $this->response->errorNotFound();
114
-    }
115
-
116
-    /**
117
-     * Log the user out
118
-     * 
119
-     * @param  string $apiKey
120
-     * @return \Illuminate\Http\JsonResponse
121
-     */
122
-    public function deauthenticate($apiKey) 
123
-    {
124
-        $this->apiKey = ApiKey::where('key', $apiKey)->first();
125
-
126
-        if (empty($this->apiKey)) {
127
-            return $this->response->errorUnauthorized("There is no such user to deauthenticate.");
128
-        }
129
-
130
-        $this->apiKey->delete();
131
-
132
-        return $this->response->withArray([
133
-            'ok' => [
134
-                'code'      => 'SUCCESSFUL',
135
-                'http_code' => 200,
136
-                'message'   => 'User was successfuly deauthenticated'
137
-            ]
138
-        ]);
139
-    }
85
+		if (!isset($apiKey)) {
86
+			$apiKey                = new ApiKey;
87
+			$apiKey->user_id       = $user->id;
88
+			$apiKey->key           = $apiKey->generateKey();
89
+			$apiKey->level         = 5;
90
+			$apiKey->ignore_limits = 0;
91
+		} else {
92
+			$apiKey->generateKey();
93
+		}
94
+
95
+		if (!$apiKey->save()) {
96
+			return $this->response->errorInternalError("Failed to create an API key. Please try again.");
97
+		}
98
+
99
+
100
+		// We have an API key.. i guess we only need to return that.
101
+		return $this->response->withItem($user, new \App\LaravelRestCms\User\UserTransformer);
102
+	}
103
+
104
+	/**
105
+	 * Retrieve the user model
106
+	 * 
107
+	 * @return Model
108
+	 */
109
+	public function getUserDetails() 
110
+	{
111
+		$user = $this->apiKey->user;
112
+
113
+		return isset($user) ? $user : $this->response->errorNotFound();
114
+	}
115
+
116
+	/**
117
+	 * Log the user out
118
+	 * 
119
+	 * @param  string $apiKey
120
+	 * @return \Illuminate\Http\JsonResponse
121
+	 */
122
+	public function deauthenticate($apiKey) 
123
+	{
124
+		$this->apiKey = ApiKey::where('key', $apiKey)->first();
125
+
126
+		if (empty($this->apiKey)) {
127
+			return $this->response->errorUnauthorized("There is no such user to deauthenticate.");
128
+		}
129
+
130
+		$this->apiKey->delete();
131
+
132
+		return $this->response->withArray([
133
+			'ok' => [
134
+				'code'      => 'SUCCESSFUL',
135
+				'http_code' => 200,
136
+				'message'   => 'User was successfuly deauthenticated'
137
+			]
138
+		]);
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.