| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -143,14 +143,25 @@ public function user() | |||
| 143 | 143 | ||
| 144 | 144 | if (is_null($user) && ! is_null($recaller)) | |
| 145 | 145 | { | |
| 146 | - $user = $this->provider->retrieveByID($recaller); | ||
| 147 | - | ||
| 148 | - $this->viaRemember = ! is_null($user); | ||
| 146 | + $user = $this->getUserByRecaller($recaller); | ||
| 149 | 147 | } | |
| 150 | 148 | ||
| 151 | 149 | return $this->user = $user; | |
| 152 | 150 | } | |
| 153 | 151 | ||
| 152 | + /** | ||
| 153 | + * Pull a user from the repository by its recaller ID. | ||
| 154 | + * | ||
| 155 | + * @param mixed $id | ||
| 156 | + * @return mixed | ||
| 157 | + */ | ||
| 158 | + protected function getUserByRecaller($id) | ||
| 159 | + { | ||
| 160 | + $this->viaRemember = ! is_null($user = $this->provider->retrieveByID($id)); | ||
| 161 | + | ||
| 162 | + return $user; | ||
| 163 | + } | ||
| 164 | + | ||
| 154 | 165 | /** | |
| 155 | 166 | * Get the decrypted recaller cookie for the request. | |
| 156 | 167 | * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -152,7 +152,12 @@ public function forever($key, $value) | |||
| 152 | 152 | */ | |
| 153 | 153 | public function forget($key) | |
| 154 | 154 | { | |
| 155 | - $this->files->delete($this->path($key)); | ||
| 155 | + $file = $this->path($key); | ||
| 156 | + | ||
| 157 | + if ($this->files->exists($file)) | ||
| 158 | + { | ||
| 159 | + $this->files->delete($file); | ||
| 160 | + } | ||
| 156 | 161 | } | |
| 157 | 162 | ||
| 158 | 163 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,13 @@ class Repository implements ArrayAccess { | |||
| 21 | 21 | */ | |
| 22 | 22 | protected $default = 60; | |
| 23 | 23 | ||
| 24 | + /** | ||
| 25 | + * An array of registered Cache macros. | ||
| 26 | + * | ||
| 27 | + * @var array | ||
| 28 | + */ | ||
| 29 | + protected $macros = array(); | ||
| 30 | + | ||
| 24 | 31 | /** | |
| 25 | 32 | * Create a new cache repository instance. | |
| 26 | 33 | * | |
@@ -243,15 +250,35 @@ protected function getMinutes($duration) | |||
| 243 | 250 | } | |
| 244 | 251 | ||
| 245 | 252 | /** | |
| 246 | - * Dynamically pass missing methods to the store. | ||
| 253 | + * Register a macro with the Cache class. | ||
| 254 | + * | ||
| 255 | + * @param string $name | ||
| 256 | + * @param callable $callback | ||
| 257 | + * @return void | ||
| 258 | + */ | ||
| 259 | + public function macro($name, $callback) | ||
| 260 | + { | ||
| 261 | + $this->macros[$name] = $callback; | ||
| 262 | + } | ||
| 263 | + | ||
| 264 | + /** | ||
| 265 | + * Handle dynamic calls into macros or pass missing methods to the store. | ||
| 247 | 266 | * | |
| 248 | 267 | * @param string $method | |
| 249 | - * @param array $parameters | ||
| 268 | + * @param array $parameters | ||
| 250 | 269 | * @return mixed | |
| 251 | 270 | */ | |
| 252 | 271 | public function __call($method, $parameters) | |
| 253 | 272 | { | |
| 254 | - return call_user_func_array(array($this->store, $method), $parameters); | ||
| 273 | + if (isset($this->macros[$method])) | ||
| 274 | + { | ||
| 275 | + return call_user_func_array($this->macros[$method], $parameters); | ||
| 276 | + } | ||
| 277 | + else | ||
| 278 | + { | ||
| 279 | + return call_user_func_array(array($this->store, $method), $parameters); | ||
| 280 | + } | ||
| 255 | 281 | } | |
| 256 | 282 | ||
| 283 | + | ||
| 257 | 284 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,6 +69,24 @@ public function put($key, $value, $minutes) | |||
| 69 | 69 | return $this->store->put($this->taggedItemKey($key), $value, $minutes); | |
| 70 | 70 | } | |
| 71 | 71 | ||
| 72 | + /** | ||
| 73 | + * Store an item in the cache if the key does not exist. | ||
| 74 | + * | ||
| 75 | + * @param string $key | ||
| 76 | + * @param mixed $value | ||
| 77 | + * @param Carbon|Datetime|int $minutes | ||
| 78 | + * @return bool | ||
| 79 | + */ | ||
| 80 | + public function add($key, $value, $minutes) | ||
| 81 | + { | ||
| 82 | + if (is_null($this->get($key))) | ||
| 83 | + { | ||
| 84 | + $this->put($key, $value, $minutes); return true; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + return false; | ||
| 88 | + } | ||
| 89 | + | ||
| 72 | 90 | /** | |
| 73 | 91 | * Increment the value of an item in the cache. | |
| 74 | 92 | * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -580,6 +580,46 @@ protected function isNested($name, $relation) | |||
| 580 | 580 | return $dots && starts_with($name, $relation) && $name != $relation; | |
| 581 | 581 | } | |
| 582 | 582 | ||
| 583 | + /** | ||
| 584 | + * Add a basic where clause to the query. | ||
| 585 | + * | ||
| 586 | + * @param string $column | ||
| 587 | + * @param string $operator | ||
| 588 | + * @param mixed $value | ||
| 589 | + * @param string $boolean | ||
| 590 | + * @return \Illuminate\Database\Eloquent\Builder|static | ||
| 591 | + */ | ||
| 592 | + public function where($column, $operator = null, $value = null, $boolean = 'and') | ||
| 593 | + { | ||
| 594 | + if ($column instanceof Closure) | ||
| 595 | + { | ||
| 596 | + $query = $this->model->newQuery(); | ||
| 597 | + | ||
| 598 | + call_user_func($column, $query); | ||
| 599 | + | ||
| 600 | + $this->query->addNestedWhereQuery($query->getQuery(), $boolean); | ||
| 601 | + } | ||
| 602 | + else | ||
| 603 | + { | ||
| 604 | + $this->query->where($column, $operator, $value, $boolean); | ||
| 605 | + } | ||
| 606 | + | ||
| 607 | + return $this; | ||
| 608 | + } | ||
| 609 | + | ||
| 610 | + /** | ||
| 611 | + * Add an "or where" clause to the query. | ||
| 612 | + * | ||
| 613 | + * @param string $column | ||
| 614 | + * @param string $operator | ||
| 615 | + * @param mixed $value | ||
| 616 | + * @return \Illuminate\Database\Eloquent\Builder|static | ||
| 617 | + */ | ||
| 618 | + public function orWhere($column, $operator = null, $value = null) | ||
| 619 | + { | ||
| 620 | + return $this->where($column, $operator, $value, 'or'); | ||
| 621 | + } | ||
| 622 | + | ||
| 583 | 623 | /** | |
| 584 | 624 | * Add a relationship count condition to the query. | |
| 585 | 625 | * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -503,6 +503,8 @@ public static function all($columns = array('*')) | |||
| 503 | 503 | */ | |
| 504 | 504 | public static function find($id, $columns = array('*')) | |
| 505 | 505 | { | |
| 506 | + if (is_array($id) && empty($id)) return new Collection; | ||
| 507 | + | ||
| 506 | 508 | $instance = new static; | |
| 507 | 509 | ||
| 508 | 510 | return $instance->newQuery()->find($id, $columns); | |
@@ -752,8 +754,6 @@ public function belongsToMany($related, $table = null, $foreignKey = null, $othe | |||
| 752 | 754 | if (is_null($relation)) | |
| 753 | 755 | { | |
| 754 | 756 | $caller = $this->getBelongsToManyCaller(); | |
| 755 | - | ||
| 756 | - $name = $caller['function']; | ||
| 757 | 757 | } | |
| 758 | 758 | ||
| 759 | 759 | // First, we'll need to determine the foreign key and "other key" for the | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -843,7 +843,7 @@ protected function touchingParent() | |||
| 843 | 843 | */ | |
| 844 | 844 | protected function guessInverseRelation() | |
| 845 | 845 | { | |
| 846 | - return strtolower(str_plural(class_basename($this->getParent()))); | ||
| 846 | + return camel_case(str_plural(class_basename($this->getParent()))); | ||
| 847 | 847 | } | |
| 848 | 848 | ||
| 849 | 849 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,7 +82,7 @@ public function log($file, $batch) | |||
| 82 | 82 | */ | |
| 83 | 83 | public function delete($migration) | |
| 84 | 84 | { | |
| 85 | - $query = $this->table()->where('migration', $migration->migration)->delete(); | ||
| 85 | + $this->table()->where('migration', $migration->migration)->delete(); | ||
| 86 | 86 | } | |
| 87 | 87 | ||
| 88 | 88 | /** | |
@@ -178,4 +178,4 @@ public function setSource($name) | |||
| 178 | 178 | $this->connection = $name; | |
| 179 | 179 | } | |
| 180 | 180 | ||
| 181 | - } | ||
| 181 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -514,19 +514,28 @@ public function whereNested(Closure $callback, $boolean = 'and') | |||
| 514 | 514 | // To handle nested queries we'll actually create a brand new query instance | |
| 515 | 515 | // and pass it off to the Closure that we have. The Closure can simply do | |
| 516 | 516 | // do whatever it wants to a query then we will store it for compiling. | |
| 517 | - $type = 'Nested'; | ||
| 518 | - | ||
| 519 | 517 | $query = $this->newQuery(); | |
| 520 | 518 | ||
| 521 | 519 | $query->from($this->from); | |
| 522 | 520 | ||
| 523 | 521 | call_user_func($callback, $query); | |
| 524 | 522 | ||
| 525 | - // Once we have let the Closure do its things, we can gather the bindings on | ||
| 526 | - // the nested query builder and merge them into these bindings since they | ||
| 527 | - // need to get extracted out of the children and assigned to the array. | ||
| 523 | + return $this->addNestedWhereQuery($query, $boolean); | ||
| 524 | + } | ||
| 525 | + | ||
| 526 | + /** | ||
| 527 | + * Add another query builder as a nested where to the query builder. | ||
| 528 | + * | ||
| 529 | + * @param \Illuminate\Database\Query\Builder|static $query | ||
| 530 | + * @param string $boolean | ||
| 531 | + * @return \Illuminate\Database\Query\Builder|static | ||
| 532 | + */ | ||
| 533 | + public function addNestedWhereQuery($query, $boolean = 'and') | ||
| 534 | + { | ||
| 528 | 535 | if (count($query->wheres)) | |
| 529 | 536 | { | |
| 537 | + $type = 'Nested'; | ||
| 538 | + | ||
| 530 | 539 | $this->wheres[] = compact('type', 'query', 'boolean'); | |
| 531 | 540 | ||
| 532 | 541 | $this->mergeBindings($query); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -410,8 +410,6 @@ protected function compileGroups(Builder $query, $groups) | |||
| 410 | 410 | */ | |
| 411 | 411 | protected function compileHavings(Builder $query, $havings) | |
| 412 | 412 | { | |
| 413 | - $me = $this; | ||
| 414 | - | ||
| 415 | 413 | $sql = implode(' ', array_map(array($this, 'compileHaving'), $havings)); | |
| 416 | 414 | ||
| 417 | 415 | return 'having '.preg_replace('/and /', '', $sql, 1); | |
@@ -679,4 +677,4 @@ protected function removeLeadingBoolean($value) | |||
| 679 | 677 | return preg_replace('/and |or /', '', $value, 1); | |
| 680 | 678 | } | |
| 681 | 679 | ||
| 682 | - } | ||
| 680 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments