@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | { |
| 32 | 32 | // merge default config |
| 33 | 33 | $this->mergeConfigFrom( |
| 34 | - __DIR__.$this->configPath , 'repositories' |
|
| 34 | + __DIR__.$this->configPath, 'repositories' |
|
| 35 | 35 | ); |
| 36 | 36 | |
| 37 | 37 | // Bind the repositories. |
@@ -49,43 +49,43 @@ discard block |
||
| 49 | 49 | private function autoBindRepositories() |
| 50 | 50 | { |
| 51 | 51 | // Load config parameters needed. |
| 52 | - $repositoriesBasePath = config( 'repositories.repositories_path' ); |
|
| 53 | - $baseNamespace = rtrim( config( 'repositories.repository_interfaces_namespace' ), '\\' ) . '\\'; |
|
| 54 | - $skipRepositories = config( 'repositories.skip' ); |
|
| 55 | - $implementationBindings = config( 'repositories.bindings' ); |
|
| 56 | - $implementation = $this->findDefaultImplementation( $implementationBindings ); |
|
| 52 | + $repositoriesBasePath = config('repositories.repositories_path'); |
|
| 53 | + $baseNamespace = rtrim(config('repositories.repository_interfaces_namespace'), '\\').'\\'; |
|
| 54 | + $skipRepositories = config('repositories.skip'); |
|
| 55 | + $implementationBindings = config('repositories.bindings'); |
|
| 56 | + $implementation = $this->findDefaultImplementation($implementationBindings); |
|
| 57 | 57 | |
| 58 | - if ( \File::exists( $repositoriesBasePath ) ) |
|
| 58 | + if (\File::exists($repositoriesBasePath)) |
|
| 59 | 59 | { |
| 60 | - $allRepos = \File::files( $repositoriesBasePath ); |
|
| 60 | + $allRepos = \File::files($repositoriesBasePath); |
|
| 61 | 61 | |
| 62 | - foreach( $allRepos as $repo ) |
|
| 62 | + foreach ($allRepos as $repo) |
|
| 63 | 63 | { |
| 64 | - $interfaceName = pathinfo( $repo, PATHINFO_FILENAME ); |
|
| 65 | - if ( in_array( $interfaceName, $skipRepositories ) ) continue; |
|
| 64 | + $interfaceName = pathinfo($repo, PATHINFO_FILENAME); |
|
| 65 | + if (in_array($interfaceName, $skipRepositories)) continue; |
|
| 66 | 66 | else |
| 67 | 67 | { |
| 68 | - $commonName = str_replace( 'Interface', '', $interfaceName ); |
|
| 68 | + $commonName = str_replace('Interface', '', $interfaceName); |
|
| 69 | 69 | $interfaceFullClassName = $baseNamespace.$interfaceName; |
| 70 | 70 | |
| 71 | - foreach( $implementationBindings as $engine => $bindRepositories ) |
|
| 71 | + foreach ($implementationBindings as $engine => $bindRepositories) |
|
| 72 | 72 | { |
| 73 | - if ( $bindRepositories === 'default' ) continue; |
|
| 74 | - else if ( in_array( $interfaceName, $bindRepositories ) ) |
|
| 73 | + if ($bindRepositories === 'default') continue; |
|
| 74 | + else if (in_array($interfaceName, $bindRepositories)) |
|
| 75 | 75 | { |
| 76 | 76 | $implementation = $engine; |
| 77 | 77 | break; |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - $fullClassName = $baseNamespace.ucfirst( camel_case( $implementation ) ).'\\'.$commonName; |
|
| 81 | + $fullClassName = $baseNamespace.ucfirst(camel_case($implementation)).'\\'.$commonName; |
|
| 82 | 82 | |
| 83 | - if ( class_exists( $fullClassName ) ) |
|
| 83 | + if (class_exists($fullClassName)) |
|
| 84 | 84 | { |
| 85 | 85 | // Bind the class. |
| 86 | - $this->app->bind( $interfaceFullClassName, function ( $app ) use ( $fullClassName ) |
|
| 86 | + $this->app->bind($interfaceFullClassName, function($app) use ($fullClassName) |
|
| 87 | 87 | { |
| 88 | - return $app->make( $fullClassName ); |
|
| 88 | + return $app->make($fullClassName); |
|
| 89 | 89 | }); |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | * @param $implementations |
| 99 | 99 | * @return array|mixed|string |
| 100 | 100 | */ |
| 101 | - private function findDefaultImplementation( $implementations ) |
|
| 101 | + private function findDefaultImplementation($implementations) |
|
| 102 | 102 | { |
| 103 | - $filtered = array_filter( $implementations, function( $k ) { |
|
| 103 | + $filtered = array_filter($implementations, function($k) { |
|
| 104 | 104 | return $k === 'default'; |
| 105 | 105 | }); |
| 106 | 106 | |
| 107 | 107 | $default = array_keys($filtered); |
| 108 | - $default = is_array( $default ) ? $default[0] : $default; |
|
| 108 | + $default = is_array($default) ? $default[0] : $default; |
|
| 109 | 109 | |
| 110 | 110 | return $default ? $default : 'eloquent'; |
| 111 | 111 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | private function registerRepositoryGenerator() |
| 117 | 117 | { |
| 118 | - $this->app->singleton('command.repository', function ($app) |
|
| 118 | + $this->app->singleton('command.repository', function($app) |
|
| 119 | 119 | { |
| 120 | 120 | return $app['OkayBueno\Repositories\Commands\MakeRepositoryCommand']; |
| 121 | 121 | }); |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | private function registerCriteriaGenerator() |
| 131 | 131 | { |
| 132 | - $this->app->singleton('command.criteria', function ($app) |
|
| 132 | + $this->app->singleton('command.criteria', function($app) |
|
| 133 | 133 | { |
| 134 | 134 | return $app['OkayBueno\Repositories\Commands\MakeCriteriaCommand']; |
| 135 | 135 | }); |
@@ -62,16 +62,18 @@ |
||
| 62 | 62 | foreach( $allRepos as $repo ) |
| 63 | 63 | { |
| 64 | 64 | $interfaceName = pathinfo( $repo, PATHINFO_FILENAME ); |
| 65 | - if ( in_array( $interfaceName, $skipRepositories ) ) continue; |
|
| 66 | - else |
|
| 65 | + if ( in_array( $interfaceName, $skipRepositories ) ) { |
|
| 66 | + continue; |
|
| 67 | + } else |
|
| 67 | 68 | { |
| 68 | 69 | $commonName = str_replace( 'Interface', '', $interfaceName ); |
| 69 | 70 | $interfaceFullClassName = $baseNamespace.$interfaceName; |
| 70 | 71 | |
| 71 | 72 | foreach( $implementationBindings as $engine => $bindRepositories ) |
| 72 | 73 | { |
| 73 | - if ( $bindRepositories === 'default' ) continue; |
|
| 74 | - else if ( in_array( $interfaceName, $bindRepositories ) ) |
|
| 74 | + if ( $bindRepositories === 'default' ) { |
|
| 75 | + continue; |
|
| 76 | + } else if ( in_array( $interfaceName, $bindRepositories ) ) |
|
| 75 | 77 | { |
| 76 | 78 | $implementation = $engine; |
| 77 | 79 | break; |
@@ -22,12 +22,12 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * @param Model $model |
| 24 | 24 | */ |
| 25 | - public function __construct( Model $model ) |
|
| 25 | + public function __construct(Model $model) |
|
| 26 | 26 | { |
| 27 | 27 | $this->model = $model; |
| 28 | 28 | |
| 29 | 29 | // A clean copy of the model is needed when the scope needs to be reset. |
| 30 | - $reflex = new \ReflectionClass( $model ); |
|
| 30 | + $reflex = new \ReflectionClass($model); |
|
| 31 | 31 | $this->modelClassName = $reflex->getName(); |
| 32 | 32 | |
| 33 | 33 | $this->skipCriteria = FALSE; |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | $this->eagerLoadRelations(); |
| 46 | 46 | $this->applyCriteria(); |
| 47 | 47 | |
| 48 | - if ( !is_null( $value ) ) $this->model = $this->model->where( $field, $value ); |
|
| 48 | + if (!is_null($value)) $this->model = $this->model->where($field, $value); |
|
| 49 | 49 | |
| 50 | - $result = $this->model->first( $columns ); |
|
| 50 | + $result = $this->model->first($columns); |
|
| 51 | 51 | |
| 52 | 52 | $this->resetScope(); |
| 53 | 53 | |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | $this->eagerLoadRelations(); |
| 66 | 66 | $this->applyCriteria(); |
| 67 | 67 | |
| 68 | - if ( !is_null( $value ) && !is_null( $field ) ) $this->model = $this->model->where( $field, $value ); |
|
| 68 | + if (!is_null($value) && !is_null($field)) $this->model = $this->model->where($field, $value); |
|
| 69 | 69 | |
| 70 | - $result = $this->model->get( $columns ); |
|
| 70 | + $result = $this->model->get($columns); |
|
| 71 | 71 | |
| 72 | 72 | $this->resetScope(); |
| 73 | 73 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | { |
| 85 | 85 | $this->eagerLoadRelations(); |
| 86 | 86 | $this->applyCriteria(); |
| 87 | - $result = $this->model->whereIn( $field, $value )->get( $columns ); |
|
| 87 | + $result = $this->model->whereIn($field, $value)->get($columns); |
|
| 88 | 88 | |
| 89 | 89 | $this->resetScope(); |
| 90 | 90 | |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | * @param array $columns |
| 96 | 96 | * @return \Illuminate\Database\Eloquent\Collection|static[] |
| 97 | 97 | */ |
| 98 | - public function findAll( array $columns = ['*'] ) |
|
| 98 | + public function findAll(array $columns = ['*']) |
|
| 99 | 99 | { |
| 100 | 100 | $this->eagerLoadRelations(); |
| 101 | - $result = $this->model->all( $columns ); |
|
| 101 | + $result = $this->model->all($columns); |
|
| 102 | 102 | |
| 103 | 103 | $this->resetScope(); |
| 104 | 104 | |
@@ -109,9 +109,9 @@ discard block |
||
| 109 | 109 | * @param array|string $relations |
| 110 | 110 | * @return $this |
| 111 | 111 | */ |
| 112 | - public function with( $relations ) |
|
| 112 | + public function with($relations) |
|
| 113 | 113 | { |
| 114 | - if ( is_string( $relations ) ) $relations = func_get_args(); |
|
| 114 | + if (is_string($relations)) $relations = func_get_args(); |
|
| 115 | 115 | |
| 116 | 116 | $this->with = $relations; |
| 117 | 117 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @param CriteriaInterface $criteria |
| 124 | 124 | * @return $this |
| 125 | 125 | */ |
| 126 | - public function addCriteria( CriteriaInterface $criteria) |
|
| 126 | + public function addCriteria(CriteriaInterface $criteria) |
|
| 127 | 127 | { |
| 128 | 128 | $this->criteria[] = $criteria; |
| 129 | 129 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @param bool $status |
| 136 | 136 | * @return $this |
| 137 | 137 | */ |
| 138 | - public function skipCriteria( $status = TRUE ) |
|
| 138 | + public function skipCriteria($status = TRUE) |
|
| 139 | 139 | { |
| 140 | 140 | $this->skipCriteria = $status; |
| 141 | 141 | return $this; |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | { |
| 152 | 152 | $this->eagerLoadRelations(); |
| 153 | 153 | $this->applyCriteria(); |
| 154 | - $result = $this->model->paginate( $perPage, $columns ); |
|
| 154 | + $result = $this->model->paginate($perPage, $columns); |
|
| 155 | 155 | |
| 156 | 156 | $this->resetScope(); |
| 157 | 157 | |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | * @param int $currentPage |
| 164 | 164 | * @return $this |
| 165 | 165 | */ |
| 166 | - public function setCurrentPage( $currentPage ) |
|
| 166 | + public function setCurrentPage($currentPage) |
|
| 167 | 167 | { |
| 168 | - \Illuminate\Pagination\Paginator::currentPageResolver(function() use ( $currentPage ) |
|
| 168 | + \Illuminate\Pagination\Paginator::currentPageResolver(function() use ($currentPage) |
|
| 169 | 169 | { |
| 170 | 170 | return $currentPage; |
| 171 | 171 | }); |
@@ -180,9 +180,9 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | public function create(array $data) |
| 182 | 182 | { |
| 183 | - $cleanFields = $this->cleanUnfillableFields( $data ); |
|
| 183 | + $cleanFields = $this->cleanUnfillableFields($data); |
|
| 184 | 184 | |
| 185 | - $createdObject = $this->model->create( $cleanFields ); |
|
| 185 | + $createdObject = $this->model->create($cleanFields); |
|
| 186 | 186 | |
| 187 | 187 | $this->resetScope(); |
| 188 | 188 | |
@@ -197,14 +197,14 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | public function updateBy(array $data, $value = NULL, $field = 'id') |
| 199 | 199 | { |
| 200 | - $cleanFields = $this->cleanUnfillableFields( $data ); |
|
| 200 | + $cleanFields = $this->cleanUnfillableFields($data); |
|
| 201 | 201 | |
| 202 | - if ( !is_null( $value ) ) |
|
| 202 | + if (!is_null($value)) |
|
| 203 | 203 | { |
| 204 | 204 | // Single update. |
| 205 | - $this->model->where( $field, $value)->update( $cleanFields ); |
|
| 205 | + $this->model->where($field, $value)->update($cleanFields); |
|
| 206 | 206 | |
| 207 | - foreach( $cleanFields as $F => $V ) $this->model->{$F} = $V; |
|
| 207 | + foreach ($cleanFields as $F => $V) $this->model->{$F} = $V; |
|
| 208 | 208 | |
| 209 | 209 | $returnedVal = $this->model; |
| 210 | 210 | } else |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | // Mass update. |
| 213 | 213 | $this->applyCriteria(); |
| 214 | 214 | |
| 215 | - $returnedVal = $this->model->update( $cleanFields ); |
|
| 215 | + $returnedVal = $this->model->update($cleanFields); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | $this->resetScope(); |
@@ -225,14 +225,14 @@ discard block |
||
| 225 | 225 | * @param string $field |
| 226 | 226 | * @return bool |
| 227 | 227 | */ |
| 228 | - public function delete( $value = null, $field = 'id' ) |
|
| 228 | + public function delete($value = null, $field = 'id') |
|
| 229 | 229 | { |
| 230 | 230 | $this->applyCriteria(); |
| 231 | 231 | |
| 232 | - if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->delete(); |
|
| 232 | + if (!is_null($value)) $result = $this->model->where($field, $value)->delete(); |
|
| 233 | 233 | else |
| 234 | 234 | { |
| 235 | - if ( !empty( $this->criteria ) ) $result = $this->model->delete(); |
|
| 235 | + if (!empty($this->criteria)) $result = $this->model->delete(); |
|
| 236 | 236 | else $result = FALSE; |
| 237 | 237 | } |
| 238 | 238 | |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | public function resetScope() |
| 261 | 261 | { |
| 262 | 262 | $this->criteria = []; |
| 263 | - $this->skipCriteria( FALSE ); |
|
| 263 | + $this->skipCriteria(FALSE); |
|
| 264 | 264 | $this->model = new $this->modelClassName(); |
| 265 | 265 | return $this; |
| 266 | 266 | } |
@@ -274,10 +274,10 @@ discard block |
||
| 274 | 274 | { |
| 275 | 275 | $this->applyCriteria(); |
| 276 | 276 | |
| 277 | - if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->forceDelete(); |
|
| 277 | + if (!is_null($value)) $result = $this->model->where($field, $value)->forceDelete(); |
|
| 278 | 278 | else |
| 279 | 279 | { |
| 280 | - if ( !empty( $this->criteria ) ) $result = $this->model->forceDelete(); |
|
| 280 | + if (!empty($this->criteria)) $result = $this->model->forceDelete(); |
|
| 281 | 281 | else $result = FALSE; |
| 282 | 282 | } |
| 283 | 283 | |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | protected function eagerLoadRelations() |
| 298 | 298 | { |
| 299 | - if ( is_array( $this->with ) ) $this->model->with( $this->with ); |
|
| 299 | + if (is_array($this->with)) $this->model->with($this->with); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | |
@@ -304,13 +304,13 @@ discard block |
||
| 304 | 304 | * @param array $data |
| 305 | 305 | * @return array |
| 306 | 306 | */ |
| 307 | - private function cleanUnfillableFields( array $data ) |
|
| 307 | + private function cleanUnfillableFields(array $data) |
|
| 308 | 308 | { |
| 309 | 309 | $fillableFields = $this->model->getFillable(); |
| 310 | 310 | |
| 311 | - foreach( $data as $key => $value ) |
|
| 311 | + foreach ($data as $key => $value) |
|
| 312 | 312 | { |
| 313 | - if ( !in_array( $key, $fillableFields ) ) unset( $data[ $key ] ); |
|
| 313 | + if (!in_array($key, $fillableFields)) unset($data[$key]); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | return $data; |
@@ -321,11 +321,11 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | private function applyCriteria() |
| 323 | 323 | { |
| 324 | - if( !$this->skipCriteria ) |
|
| 324 | + if (!$this->skipCriteria) |
|
| 325 | 325 | { |
| 326 | - foreach( $this->criteria as $criteria ) |
|
| 326 | + foreach ($this->criteria as $criteria) |
|
| 327 | 327 | { |
| 328 | - if( $criteria instanceof CriteriaInterface ) $this->model = $criteria->apply( $this->model, $this ); |
|
| 328 | + if ($criteria instanceof CriteriaInterface) $this->model = $criteria->apply($this->model, $this); |
|
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | |
@@ -45,7 +45,9 @@ discard block |
||
| 45 | 45 | $this->eagerLoadRelations(); |
| 46 | 46 | $this->applyCriteria(); |
| 47 | 47 | |
| 48 | - if ( !is_null( $value ) ) $this->model = $this->model->where( $field, $value ); |
|
| 48 | + if ( !is_null( $value ) ) { |
|
| 49 | + $this->model = $this->model->where( $field, $value ); |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | $result = $this->model->first( $columns ); |
| 51 | 53 | |
@@ -65,7 +67,9 @@ discard block |
||
| 65 | 67 | $this->eagerLoadRelations(); |
| 66 | 68 | $this->applyCriteria(); |
| 67 | 69 | |
| 68 | - if ( !is_null( $value ) && !is_null( $field ) ) $this->model = $this->model->where( $field, $value ); |
|
| 70 | + if ( !is_null( $value ) && !is_null( $field ) ) { |
|
| 71 | + $this->model = $this->model->where( $field, $value ); |
|
| 72 | + } |
|
| 69 | 73 | |
| 70 | 74 | $result = $this->model->get( $columns ); |
| 71 | 75 | |
@@ -111,7 +115,9 @@ discard block |
||
| 111 | 115 | */ |
| 112 | 116 | public function with( $relations ) |
| 113 | 117 | { |
| 114 | - if ( is_string( $relations ) ) $relations = func_get_args(); |
|
| 118 | + if ( is_string( $relations ) ) { |
|
| 119 | + $relations = func_get_args(); |
|
| 120 | + } |
|
| 115 | 121 | |
| 116 | 122 | $this->with = $relations; |
| 117 | 123 | |
@@ -204,7 +210,9 @@ discard block |
||
| 204 | 210 | // Single update. |
| 205 | 211 | $this->model->where( $field, $value)->update( $cleanFields ); |
| 206 | 212 | |
| 207 | - foreach( $cleanFields as $F => $V ) $this->model->{$F} = $V; |
|
| 213 | + foreach( $cleanFields as $F => $V ) { |
|
| 214 | + $this->model->{$F} = $V; |
|
| 215 | + } |
|
| 208 | 216 | |
| 209 | 217 | $returnedVal = $this->model; |
| 210 | 218 | } else |
@@ -229,11 +237,15 @@ discard block |
||
| 229 | 237 | { |
| 230 | 238 | $this->applyCriteria(); |
| 231 | 239 | |
| 232 | - if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->delete(); |
|
| 233 | - else |
|
| 240 | + if ( !is_null( $value ) ) { |
|
| 241 | + $result = $this->model->where( $field, $value )->delete(); |
|
| 242 | + } else |
|
| 234 | 243 | { |
| 235 | - if ( !empty( $this->criteria ) ) $result = $this->model->delete(); |
|
| 236 | - else $result = FALSE; |
|
| 244 | + if ( !empty( $this->criteria ) ) { |
|
| 245 | + $result = $this->model->delete(); |
|
| 246 | + } else { |
|
| 247 | + $result = FALSE; |
|
| 248 | + } |
|
| 237 | 249 | } |
| 238 | 250 | |
| 239 | 251 | $this->resetScope(); |
@@ -274,11 +286,15 @@ discard block |
||
| 274 | 286 | { |
| 275 | 287 | $this->applyCriteria(); |
| 276 | 288 | |
| 277 | - if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->forceDelete(); |
|
| 278 | - else |
|
| 289 | + if ( !is_null( $value ) ) { |
|
| 290 | + $result = $this->model->where( $field, $value )->forceDelete(); |
|
| 291 | + } else |
|
| 279 | 292 | { |
| 280 | - if ( !empty( $this->criteria ) ) $result = $this->model->forceDelete(); |
|
| 281 | - else $result = FALSE; |
|
| 293 | + if ( !empty( $this->criteria ) ) { |
|
| 294 | + $result = $this->model->forceDelete(); |
|
| 295 | + } else { |
|
| 296 | + $result = FALSE; |
|
| 297 | + } |
|
| 282 | 298 | } |
| 283 | 299 | |
| 284 | 300 | $this->resetScope(); |
@@ -296,7 +312,9 @@ discard block |
||
| 296 | 312 | */ |
| 297 | 313 | protected function eagerLoadRelations() |
| 298 | 314 | { |
| 299 | - if ( is_array( $this->with ) ) $this->model->with( $this->with ); |
|
| 315 | + if ( is_array( $this->with ) ) { |
|
| 316 | + $this->model->with( $this->with ); |
|
| 317 | + } |
|
| 300 | 318 | } |
| 301 | 319 | |
| 302 | 320 | |
@@ -310,7 +328,9 @@ discard block |
||
| 310 | 328 | |
| 311 | 329 | foreach( $data as $key => $value ) |
| 312 | 330 | { |
| 313 | - if ( !in_array( $key, $fillableFields ) ) unset( $data[ $key ] ); |
|
| 331 | + if ( !in_array( $key, $fillableFields ) ) { |
|
| 332 | + unset( $data[ $key ] ); |
|
| 333 | + } |
|
| 314 | 334 | } |
| 315 | 335 | |
| 316 | 336 | return $data; |
@@ -325,7 +345,9 @@ discard block |
||
| 325 | 345 | { |
| 326 | 346 | foreach( $this->criteria as $criteria ) |
| 327 | 347 | { |
| 328 | - if( $criteria instanceof CriteriaInterface ) $this->model = $criteria->apply( $this->model, $this ); |
|
| 348 | + if( $criteria instanceof CriteriaInterface ) { |
|
| 349 | + $this->model = $criteria->apply( $this->model, $this ); |
|
| 350 | + } |
|
| 329 | 351 | } |
| 330 | 352 | } |
| 331 | 353 | |
@@ -28,15 +28,15 @@ discard block |
||
| 28 | 28 | public function handle() |
| 29 | 29 | { |
| 30 | 30 | $model = $this->argument('model'); |
| 31 | - $implementation = strtolower( $this->option('implementation') ); |
|
| 31 | + $implementation = strtolower($this->option('implementation')); |
|
| 32 | 32 | |
| 33 | - if ( class_exists( $model ) ) |
|
| 33 | + if (class_exists($model)) |
|
| 34 | 34 | { |
| 35 | - $supportedImplementations = array_keys( config( 'repositories.supported_implementations' ) ); |
|
| 35 | + $supportedImplementations = array_keys(config('repositories.supported_implementations')); |
|
| 36 | 36 | |
| 37 | - if ( $implementation ) |
|
| 37 | + if ($implementation) |
|
| 38 | 38 | { |
| 39 | - if ( !in_array( $implementation, $supportedImplementations ) ) |
|
| 39 | + if (!in_array($implementation, $supportedImplementations)) |
|
| 40 | 40 | { |
| 41 | 41 | $this->error("The implementation '$implementation' is not supported at this moment. Want me to provide support? Open an issue :)."); |
| 42 | 42 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // Populate the properties with the right values. |
| 51 | - $this->populateValuesForProperties( $model, $implementation ); |
|
| 51 | + $this->populateValuesForProperties($model, $implementation); |
|
| 52 | 52 | |
| 53 | 53 | $this->createInterface(); |
| 54 | 54 | $this->createRepository(); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $this->error( "The '$model' model does not exist. Please check that the namespace and the class name are valid."); |
|
| 64 | + $this->error("The '$model' model does not exist. Please check that the namespace and the class name are valid."); |
|
| 65 | 65 | |
| 66 | 66 | } |
| 67 | 67 | |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | * @param $model |
| 70 | 70 | * @param $implementation |
| 71 | 71 | */ |
| 72 | - protected function populateValuesForProperties( $model, $implementation ) |
|
| 72 | + protected function populateValuesForProperties($model, $implementation) |
|
| 73 | 73 | { |
| 74 | - $modelClass = new \ReflectionClass( $model ); |
|
| 74 | + $modelClass = new \ReflectionClass($model); |
|
| 75 | 75 | |
| 76 | 76 | $this->implementation = $implementation; |
| 77 | 77 | |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | $this->repositoryClassName = $this->modelClassShortName.'Repository'; |
| 82 | 82 | $this->repositoryInterfaceName = $this->repositoryClassName.'Interface'; |
| 83 | 83 | |
| 84 | - $this->repositoryInterfaceNamespace = rtrim( config( 'repositories.repository_interfaces_namespace' ), '\\' ); |
|
| 85 | - $this->repositoryClassNamespace = $this->repositoryInterfaceNamespace.'\\'.ucfirst( $implementation ); |
|
| 84 | + $this->repositoryInterfaceNamespace = rtrim(config('repositories.repository_interfaces_namespace'), '\\'); |
|
| 85 | + $this->repositoryClassNamespace = $this->repositoryInterfaceNamespace.'\\'.ucfirst($implementation); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -90,17 +90,17 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | protected function createRepository() |
| 92 | 92 | { |
| 93 | - $basePath = config( 'repositories.repositories_path' ).'/'.ucfirst( $this->implementation ); |
|
| 93 | + $basePath = config('repositories.repositories_path').'/'.ucfirst($this->implementation); |
|
| 94 | 94 | |
| 95 | 95 | $classFilePath = $basePath.'/'.$this->repositoryClassName.'.php'; |
| 96 | 96 | |
| 97 | - $this->makeDirectory( $basePath ); |
|
| 97 | + $this->makeDirectory($basePath); |
|
| 98 | 98 | |
| 99 | - if ( !$this->filesystem->exists( $classFilePath ) ) |
|
| 99 | + if (!$this->filesystem->exists($classFilePath)) |
|
| 100 | 100 | { |
| 101 | 101 | // Read the stub and replace |
| 102 | - $this->filesystem->put( $classFilePath, $this->compileRepositoryStub() ); |
|
| 103 | - $this->info("'".ucfirst( $this->implementation )."' implementation created successfully for '$this->modelClassShortName'."); |
|
| 102 | + $this->filesystem->put($classFilePath, $this->compileRepositoryStub()); |
|
| 103 | + $this->info("'".ucfirst($this->implementation)."' implementation created successfully for '$this->modelClassShortName'."); |
|
| 104 | 104 | $this->composer->dumpAutoloads(); |
| 105 | 105 | } else |
| 106 | 106 | { |
@@ -114,16 +114,16 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | protected function createInterface() |
| 116 | 116 | { |
| 117 | - $repositoriesBasePath = config( 'repositories.repositories_path' ); |
|
| 117 | + $repositoriesBasePath = config('repositories.repositories_path'); |
|
| 118 | 118 | |
| 119 | 119 | $interfaceFilePath = $repositoriesBasePath.'/'.$this->repositoryInterfaceName.'.php'; |
| 120 | 120 | |
| 121 | - $this->makeDirectory( $repositoriesBasePath ); |
|
| 121 | + $this->makeDirectory($repositoriesBasePath); |
|
| 122 | 122 | |
| 123 | - if ( !$this->filesystem->exists( $interfaceFilePath ) ) |
|
| 123 | + if (!$this->filesystem->exists($interfaceFilePath)) |
|
| 124 | 124 | { |
| 125 | 125 | // Read the stub and replace |
| 126 | - $this->filesystem->put( $interfaceFilePath, $this->compileRepositoryInterfaceStub() ); |
|
| 126 | + $this->filesystem->put($interfaceFilePath, $this->compileRepositoryInterfaceStub()); |
|
| 127 | 127 | $this->info("Interface created successfully for '$this->modelClassShortName'."); |
| 128 | 128 | $this->composer->dumpAutoloads(); |
| 129 | 129 | } else |
@@ -138,10 +138,10 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | protected function compileRepositoryInterfaceStub() |
| 140 | 140 | { |
| 141 | - $stub = $this->filesystem->get(__DIR__ . '/../stubs/repository-interface.stub'); |
|
| 141 | + $stub = $this->filesystem->get(__DIR__.'/../stubs/repository-interface.stub'); |
|
| 142 | 142 | |
| 143 | - $stub = $this->replaceInterfaceNamespace( $stub ); |
|
| 144 | - $stub = $this->replaceInterfaceName( $stub ); |
|
| 143 | + $stub = $this->replaceInterfaceNamespace($stub); |
|
| 144 | + $stub = $this->replaceInterfaceName($stub); |
|
| 145 | 145 | |
| 146 | 146 | return $stub; |
| 147 | 147 | } |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | protected function compileRepositoryStub() |
| 153 | 153 | { |
| 154 | - $stub = $this->filesystem->get(__DIR__ . '/../stubs/repository.stub'); |
|
| 154 | + $stub = $this->filesystem->get(__DIR__.'/../stubs/repository.stub'); |
|
| 155 | 155 | |
| 156 | - $stub = $this->replaceInterfaceNamespace( $stub ); |
|
| 157 | - $stub = $this->replaceInterfaceName( $stub ); |
|
| 158 | - $stub = $this->replaceParentRepositoryClassNamespaceAndName( $stub ); |
|
| 159 | - $stub = $this->replaceRepositoryClassNamespaceAndName( $stub ); |
|
| 160 | - $stub = $this->replaceModelClassNamespaceAndName( $stub ); |
|
| 156 | + $stub = $this->replaceInterfaceNamespace($stub); |
|
| 157 | + $stub = $this->replaceInterfaceName($stub); |
|
| 158 | + $stub = $this->replaceParentRepositoryClassNamespaceAndName($stub); |
|
| 159 | + $stub = $this->replaceRepositoryClassNamespaceAndName($stub); |
|
| 160 | + $stub = $this->replaceModelClassNamespaceAndName($stub); |
|
| 161 | 161 | |
| 162 | 162 | return $stub; |
| 163 | 163 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @param $stub |
| 167 | 167 | * @return $this |
| 168 | 168 | */ |
| 169 | - private function replaceInterfaceNamespace( $stub ) |
|
| 169 | + private function replaceInterfaceNamespace($stub) |
|
| 170 | 170 | { |
| 171 | 171 | return str_replace('{{repositoryInterfaceNamespace}}', $this->repositoryInterfaceNamespace, $stub); |
| 172 | 172 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * @param $stub |
| 176 | 176 | * @return mixed |
| 177 | 177 | */ |
| 178 | - private function replaceInterfaceName( $stub ) |
|
| 178 | + private function replaceInterfaceName($stub) |
|
| 179 | 179 | { |
| 180 | 180 | return str_replace('{{repositoryInterfaceName}}', $this->repositoryInterfaceName, $stub); |
| 181 | 181 | } |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | * @param $stub |
| 186 | 186 | * @return mixed |
| 187 | 187 | */ |
| 188 | - private function replaceParentRepositoryClassNamespaceAndName( $stub ) |
|
| 188 | + private function replaceParentRepositoryClassNamespaceAndName($stub) |
|
| 189 | 189 | { |
| 190 | - $implementations = config( 'repositories.supported_implementations' ); |
|
| 190 | + $implementations = config('repositories.supported_implementations'); |
|
| 191 | 191 | |
| 192 | - $parentClassImplementation = $implementations[ $this->implementation ]; |
|
| 192 | + $parentClassImplementation = $implementations[$this->implementation]; |
|
| 193 | 193 | |
| 194 | 194 | $reflex = new \ReflectionClass($parentClassImplementation); |
| 195 | 195 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @param $stub |
| 203 | 203 | * @return mixed |
| 204 | 204 | */ |
| 205 | - private function replaceRepositoryClassNamespaceAndName( $stub ) |
|
| 205 | + private function replaceRepositoryClassNamespaceAndName($stub) |
|
| 206 | 206 | { |
| 207 | 207 | $stub = str_replace('{{repositoryClassName}}', $this->repositoryClassName, $stub); |
| 208 | 208 | |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | * @param $stub |
| 215 | 215 | * @return mixed |
| 216 | 216 | */ |
| 217 | - private function replaceModelClassNamespaceAndName( $stub ) |
|
| 217 | + private function replaceModelClassNamespaceAndName($stub) |
|
| 218 | 218 | { |
| 219 | 219 | $stub = str_replace('{{modelName}}', $this->modelClassShortName, $stub); |
| 220 | 220 | |