HosipLan

Untitled

Oct 11th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. class PostMethodProvider extends Nette\Object
  2. {
  3.     const RUSSIA = 1;
  4.  
  5.     private static $methodClasses = array(
  6.         self::RUSSIA => 'RussiaPostMethod',
  7.         ...
  8.     );
  9.  
  10.     private $db;
  11.  
  12.     public function __construct($db)
  13.     {
  14.         $this->db = $db;
  15.     }
  16.  
  17.  
  18.     public function get($id)
  19.     {
  20.         $package = $this->db->table('packages')->get($id);
  21.         if (isset(self::$methodClasses[$package->postMethod])) {
  22.             $class = self::$methodClasses[$package->postMethod];
  23.             return new $class($this->db, $package);
  24.         }
  25.  
  26.         throw new InvalidArgumentException('Unknown post method');
  27.     }
  28. }
  29.  
  30.  
  31. interface PostMethod
  32. {
  33.     function getDocuments();
  34. }
  35.  
  36. class RussiaPostMethod extends Nette\Object implements PostMethod
  37. {
  38.     public function getDocuments()
  39.     {
  40.         // russian folder, create template, fill in, generate PDF. ...
  41.  
  42.         // nebo muzes jenom vrati nejaky array(soubor, parametry)
  43.         // ktery predas jinemu objektu na zpracovani a vyflusne ti to PDFko
  44.     }
  45. }
  46.  
  47.  
  48.  
  49. ////// ......
  50.  
  51.  
  52. $postMethodProvider = new PostMethodProvider($db);
  53. $postMethod = $postMethodProvider->get($idZodkazu);
  54.  
  55. $pdfGenerator = new PdfGenerator(...);
  56. $pdfResponse = $pdfGenerator->generate($postMethod->getDocuments());
  57. $this->sendResponse($pdfResponse);
Advertisement
Add Comment
Please, Sign In to add comment