Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Nov 4, 2016
1 parent e276b3d commit 2b7ab30
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/Illuminate/Support/HigherOrderCollectionProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Illuminate\Support;

class HigherOrderCollectionProxy
{
/**
* The collection being operated on.
*
* @var \Illuminate\Support\Collection
*/
protected $collection;

/**
* The method being proxied.
*
* @var string
*/
protected $method;

/**
* Create a new proxy instance.
*
* @param \Illuminate\Support\Collection $collection
* @param string $method
* @return void
*/
public function __construct(Collection $collection, $method)
{
$this->method = $method;
$this->collection = $collection;
}

/**
* Proxy accessing an attribute onto the collection items.
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
return $this->collection->{$this->method}(function($value) use ($key) {
return $value->{$key};
});
}

/**
* Proxy a method call onto the collection items.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return $this->collection->{$this->method}(function($value) use ($method, $parameters) {
return $value->{$method}(...$parameters);
});
}
}

0 comments on commit 2b7ab30

Please sign in to comment.