Created
May 6, 2012 11:12
-
-
Save patie/2621687 to your computer and use it in GitHub Desktop.
len objekt pre produkty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Author: Patrik Gmitter <[email protected]> | |
* Date: 4/30/12 | |
*/ | |
namespace Patie\Eshop\Store; | |
class Product extends \Nette\Object | |
{ | |
public $id; | |
public $name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Author: Patrik Gmitter <[email protected]> | |
* Date: 5/6/12 | |
*/ | |
namespace Patie\Eshop\Store; | |
class ProductStorage | |
{ | |
protected $cache; | |
/** | |
* @var Product | |
*/ | |
private $repository; | |
/** | |
* @var Product|NULL | |
*/ | |
private $product = NULL; | |
public function __construct(\Nette\Caching\Storages\FileStorage $storage, \Patie\Eshop\Model\ProductRepository $repository) | |
{ | |
$this->repository = $repository; | |
$this->cache = new \Nette\Caching\Cache($storage); | |
} | |
public function getProduct($id) | |
{ | |
$this->product = $this->cache->load($id); | |
if ($this->product === NULL) { | |
$dbProduct = $this->repository->find($id); | |
if (!$dbProduct) { | |
return NULL; | |
} | |
$product = new Product(); | |
$product->id = $dbProduct->id; | |
$product->name = $dbProduct->name; | |
$this->product = $this->cache->save($product->id, $product, array( | |
\Nette\Caching\Cache::TAGS => array("product/$product->id"), | |
)); | |
} | |
return $this->product; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment