Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.57 KB | None | 0 0
  1. <?php
  2.  
  3. class Magento{
  4.         private $proxy, $sessionId;
  5.         public function __construct(){
  6.                 $this->proxy = new SoapClient('http://magentohost/index.php/api/v2_soap/?wsdl');
  7.                 $this->sessionId = $this->proxy->login('username', 'passwd');
  8.         }
  9.         public function __call($name, $arguments){
  10.                 array_unshift($arguments, $this->sessionId);
  11.                 return call_user_func_array(array($this->proxy, $name), $arguments);
  12.         }
  13.  
  14. }
  15.  
  16.  
  17. class MagentoWorker extends Worker {
  18.         private $magento;
  19.         public function __construct() {
  20.  
  21.                 $this->magento = new Magento();
  22.         }
  23.         public function getMagento(){
  24.                 return $this->magento;
  25.         }
  26.  
  27. }
  28.  
  29. class MyPool extends Pool{
  30. }
  31.  
  32. function createPool($workerClass){
  33.         return new Pool(3, $workerClass);
  34. }
  35. function submitTask($pool, $run, $data = null){
  36.         $retVal = Collectable::from(function(){
  37.                 try{
  38.                         $action = $this->action;
  39.                         $action($this);
  40.                 }finally{
  41.                         $this->setGarbage();
  42.                 }
  43.         }, function ($arg, $run){
  44.                 $this->action = $run;
  45.                 $this->action_data = $arg;
  46.         }, [$data, $run]);
  47.         $pool->submit($retVal);
  48.         return $retVal;
  49. }
  50. function cleanupPool($pool){
  51.         $pool->shutdown();
  52.         $pool->collect(function($work){
  53.                 waitForWork($work);
  54.  
  55.                 return $work->isGarbage();
  56.         });
  57. }
  58.  
  59. $magento = createPool('MagentoWorker');
  60.  
  61. $productListTask = submitTask($magento, function($worker) {
  62.         try{
  63.                 $magento = $worker->worker->getMagento();
  64.         // This call fails with:
  65.         // Error finding "uri" property
  66.         // #0 [internal function]: SoapClient->__call('catalogProductL...', Array)
  67.         // #1 [internal function]: SoapClient->catalogProductList('88762fc08a29593...')
  68.         // #2 /root/xero/mageno.php(11): call_user_func_array(Array, Array)
  69.         // #3 /root/xero/test.php(121): Magento->__call('catalogProductL...', Array)
  70.         // #4 /root/xero/test.php(121): Magento->catalogProductList()
  71.         // #5 /root/xero/pool.php(37): CollectableClosure@0x7f37cf52b6c0->{closur}(Object(CollectableClosure@0x7f37cf52b6c0))
  72.         // #6 {main}something went wrong
  73.  
  74.                 $magento->catalogProductList();
  75.         }catch(Exception $e){
  76.                 echo $e->getMessage() . "\n";
  77.                 echo ($e->getTraceAsString());
  78.         }finally{
  79.                 echo "something went wrong\n";
  80.         }
  81. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement