Skip to content

Commit

Permalink
Not using the constructor anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
guiwoda committed Feb 4, 2015
1 parent fe8ef6a commit 61b23f2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 33 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ variable with this package's `Application`:

```php
// in bootstrap/start.php
$app = new Proxyvel\Application(
$app = new Proxyvel\Application;

// If you don't call this, the container will just defer to Laravel's default behavior
$app->setProxyConfiguration(
// Example Specification, build the one you need here
new Proxyvel\Specifications\ProxyEverything,
// Only instances of AbstractLazyFactory are accepted for now
Expand Down
34 changes: 22 additions & 12 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ class Application extends LaravelApplication
private $proxySpecification;

/**
* @type \ProxyManager\Factory\AbstractBaseFactory
* @type \ProxyManager\Factory\AbstractLazyFactory
*/
private $proxyFactory;

/**
* @param \Proxyvel\Contracts\ProxySpecification $proxySpecification
* @param \Proxyvel\Contracts\ProxySpecification $proxySpecification
* @param \ProxyManager\Factory\AbstractLazyFactory $proxyFactory
*/
public function __construct(ProxySpecification $proxySpecification, AbstractLazyFactory $proxyFactory)
public function setProxyConfiguration(ProxySpecification $proxySpecification, AbstractLazyFactory $proxyFactory)
{
$this->proxySpecification = $proxySpecification;
$this->proxyFactory = $proxyFactory;
$this->proxyFactory = $proxyFactory;
}

/**
Expand All @@ -34,16 +34,26 @@ public function __construct(ProxySpecification $proxySpecification, AbstractLazy
*/
public function make($abstract, $parameters = array())
{
if ($this->proxySpecification->shouldProxy($abstract))
if (
! $this->__validProxyConfiguration() ||
! $this->proxySpecification->shouldProxy($abstract)
)
{
return $this->proxyFactory->createProxy($abstract, function(& $wrappedObject, $proxy, $method, $parameters, & $initializer) use ($abstract, $parameters){
$wrappedObject = parent::make($abstract, $parameters);
$initializer = null;

return true;
});
return parent::make($abstract, $parameters);
}

return parent::make($abstract, $parameters);
return $this->proxyFactory->createProxy($abstract, function(& $wrappedObject, $proxy, $method, $parameters, & $initializer) use ($abstract, $parameters){
$wrappedObject = parent::make($abstract, $parameters);
$initializer = null;

return true;
});
}

private function __validProxyConfiguration()
{
return
$this->proxySpecification instanceof ProxySpecification &&
$this->proxyFactory instanceof AbstractLazyFactory;
}
}
34 changes: 22 additions & 12 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ class Container extends LaravelContainer
private $proxySpecification;

/**
* @type \ProxyManager\Factory\AbstractBaseFactory
* @type \ProxyManager\Factory\AbstractLazyFactory
*/
private $proxyFactory;

/**
* @param \Proxyvel\Contracts\ProxySpecification $proxySpecification
* @param \Proxyvel\Contracts\ProxySpecification $proxySpecification
* @param \ProxyManager\Factory\AbstractLazyFactory $proxyFactory
*/
public function __construct(ProxySpecification $proxySpecification, AbstractLazyFactory $proxyFactory)
public function setProxyConfiguration(ProxySpecification $proxySpecification, AbstractLazyFactory $proxyFactory)
{
$this->proxySpecification = $proxySpecification;
$this->proxyFactory = $proxyFactory;
$this->proxyFactory = $proxyFactory;
}

/**
Expand All @@ -34,16 +34,26 @@ public function __construct(ProxySpecification $proxySpecification, AbstractLazy
*/
public function make($abstract, $parameters = array())
{
if ($this->proxySpecification->shouldProxy($abstract))
if (
! $this->__validateProxyConfiguration() ||
! $this->proxySpecification->shouldProxy($abstract)
)
{
return $this->proxyFactory->createProxy($abstract, function(& $wrappedObject, $proxy, $method, $parameters, & $initializer) use ($abstract, $parameters){
$wrappedObject = parent::make($abstract, $parameters);
$initializer = null;

return true;
});
return parent::make($abstract, $parameters);
}

return parent::make($abstract, $parameters);
return $this->proxyFactory->createProxy($abstract, function(& $wrappedObject, $proxy, $method, $parameters, & $initializer) use ($abstract, $parameters){
$wrappedObject = parent::make($abstract, $parameters);
$initializer = null;

return true;
});
}

private function __validateProxyConfiguration()
{
return
$this->proxySpecification instanceof ProxySpecification &&
$this->proxyFactory instanceof AbstractLazyFactory;
}
}
7 changes: 3 additions & 4 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->app = new Application(
new ProxyNamespace(['Tests\\Fixtures']),
new LazyLoadingValueHolderFactory()
);
$this->app = new Application;

$this->app->setProxyConfiguration(new ProxyNamespace(['Tests\\Fixtures']), new LazyLoadingValueHolderFactory());
}

/** @test */
Expand Down
7 changes: 3 additions & 4 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->container = new Container(
new ProxyNamespace(['Tests\\Fixtures']),
new LazyLoadingValueHolderFactory()
);
$this->container = new Container;

$this->container->setProxyConfiguration(new ProxyNamespace(['Tests\\Fixtures']), new LazyLoadingValueHolderFactory());
}

/** @test */
Expand Down

0 comments on commit 61b23f2

Please sign in to comment.