コード例 #1
0
ファイル: LogTest.php プロジェクト: danzabar/alice
 /**
  * Test Creating the file first
  *
  * @return void
  * @author Dan Cox
  */
 public function test_createFileFirst()
 {
     $this->fs->shouldReceive('exists')->andReturn(FALSE);
     $this->config->shouldReceive('create')->andReturn($this->config);
     $this->config->shouldReceive('params')->andReturn($this->config);
     $this->config->shouldReceive('save');
     $this->log->write('file.yml', 'logname', array('data' => array()));
 }
コード例 #2
0
ファイル: PullCommand.php プロジェクト: renanrmelo/cvsgit
 /**
  * Executa comando
  *
  * @param Object $oInput
  * @param Object $oOutput
  * @access public
  * @return void
  */
 public function execute($oInput, $oOutput)
 {
     $oOutput->write("baixando atualizações...\r");
     $oComando = $this->getApplication()->execute('cvs update -dRP');
     $aRetornoComandoUpdate = $oComando->output;
     $iStatusComandoUpdate = $oComando->code;
     /**
      * Caso CVS encontre conflito, retorna erro 1
      */
     if ($iStatusComandoUpdate > 1) {
         $oOutput->writeln('<error>Erro nº ' . $iStatusComandoUpdate . ' ao execurar cvs update -dR:' . "\n" . $this->getApplication()->getLastError() . '</error>');
         return $iStatusComandoUpdate;
     }
     $oOutput->writeln(str_repeat(' ', \Shell::columns()) . "\r" . "Atualizações baixados");
     $sComandoRoot = '';
     /**
      * Senha do root
      */
     $sSenhaRoot = $this->getApplication()->getConfig('senhaRoot');
     /**
      * Executa comando como root 
      * - caso for existir senha no arquivo de configuracoes
      */
     if (!empty($sSenhaRoot)) {
         $sComandoRoot = "echo '{$sSenhaRoot}' | sudo -S ";
     }
     $oComando = $this->getApplication()->execute($sComandoRoot . 'chmod 777 -R ' . getcwd());
     $aRetornoComandoPermissoes = $oComando->output;
     $iStatusComandoPermissoes = $oComando->code;
     if ($iStatusComandoPermissoes > 0) {
         throw new Exception("Erro ao atualizar permissões dos arquivos, configura a senha do root: cvsgit config -e");
     }
 }
コード例 #3
0
ファイル: webservice.php プロジェクト: barraemme/waterwall
 /**
  * POST Request
  *
  * @return Mixed data retrieved from Request
  **/
 function _post(&$Model, $params = array())
 {
     $postHeaders = array('Host' => $this->_host, 'Connection' => 'Close', 'Content-Length' => strlen($this->_data));
     $params['headers'] = array_merge($params['headers'], $postHeaders);
     if (!isset($params['headers']['Content-Type'])) {
         $params['headers']['Content-Type'] = 'application/x-www-form-urlencoded';
     }
     $this->_formatHeaders($params['headers']);
     $request = "POST {$this->_path} HTTP/1.0\r\n";
     $request .= $this->_headers . "\r\n";
     $request .= "\r\n";
     $request .= $this->_data;
     $this->__setInfo('requestHeaders', $request);
     $this->Socket->write($request);
     $response = '';
     while ($data = $this->Socket->read()) {
         $response .= $data;
     }
     $this->_parseResponse($response);
     if ($this->__settings[$Model->name]['followRedirect'] && array_key_exists('Location', $this->response['headers'])) {
         $this->serviceConnect($Model, $this->response['headers']['Location'], $params);
         $this->_data = null;
         $this->_get($Model, $params);
     }
     return $this->response['body'];
 }
コード例 #4
0
ファイル: SSH.php プロジェクト: emijrp/Peachy
 /**
  * Opens an interactive shell if not done already and transmits commands and returns output.
  *
  * @access public
  * @param string $command Command to execute
  * @param string $expect String of output to expect and remove from output.
  * @param bool $expectregex Switches string expectation to regular expressions.
  * @returns bool|string
  */
 public function iexec($command, $expect = "", $expectregex = false)
 {
     trim($command, "\n");
     if ($this->sshobject->write($command . "\n")) {
         return $this->sshobject->read($expect, $expectregex ? NET_SSH . $this->protocol . _READ_REGEX : NET_SSH . $this->protocol . _READ_SIMPLE);
     } else {
         return false;
     }
 }
コード例 #5
0
 /**
  * Gets or creates the current order.
  * IMPORTANT FUNCTION!
  * @todo - does this need to be public????
  * @return void
  */
 public function currentOrder()
 {
     if (!$this->order) {
         $sessionVariableName = $this->sessionVariableName("OrderID");
         $orderIDFromSession = intval(Session::get($sessionVariableName));
         if ($orderIDFromSession > 0) {
             $this->order = DataObject::get_by_id("Order", $orderIDFromSession);
         }
         //order has already been submitted - immediately remove it because we dont want to change it.
         $member = Member::currentUser();
         if ($this->order) {
             //first reason to set to null: it is already submitted
             if ($this->order->IsSubmitted()) {
                 $this->order = null;
             } elseif (!$this->order->canView()) {
                 $this->order = null;
             } elseif ($member && $member->exists()) {
                 if ($this->order->MemberID != $member->ID) {
                     $updateMember = false;
                     if (!$this->order->MemberID) {
                         $updateMember = true;
                     }
                     if (!$member->IsShopAdmin()) {
                         $updateMember = true;
                     }
                     if ($updateMember) {
                         $this->order->MemberID = $member->ID;
                         $this->order->write();
                     }
                 }
                 //current order has nothing in it AND the member already has an order: use the old one first
                 if ($this->order->StatusID) {
                     $firstStep = DataObject::get_one("OrderStep");
                     //we assume the first step always exists.
                     //TODO: what sort order?
                     $previousOrderFromMember = DataObject::get_one("Order", "\r\n\t\t\t\t\t\t\t\t\"MemberID\" = " . $member->ID . "\r\n\t\t\t\t\t\t\t\tAND (\"StatusID\" = " . $firstStep->ID . " OR \"StatusID\" = 0)\r\n\t\t\t\t\t\t\t\tAND \"Order\".\"ID\" <> " . $this->order->ID);
                     if ($previousOrderFromMember && $previousOrderFromMember->canView()) {
                         if ($previousOrderFromMember->StatusID) {
                             $this->order->delete();
                             $this->order = $previousOrderFromMember;
                         } else {
                             $previousOrderFromMember->delete();
                         }
                     }
                 }
             }
         }
         if (!$this->order) {
             if ($member) {
                 $firstStep = DataObject::get_one("OrderStep");
                 $previousOrderFromMember = DataObject::get_one("Order", "\"MemberID\" = " . $member->ID . " AND (\"StatusID\" = " . $firstStep->ID . " OR \"StatusID\" = 0)");
                 if ($previousOrderFromMember) {
                     if ($previousOrderFromMember->canView()) {
                         $this->order = $previousOrderFromMember;
                     }
                 }
             }
             if (!$this->order) {
                 //here we cleanup old orders, because they should be cleaned at the same rate that they are created...
                 $cleanUpEveryTime = EcommerceConfig::get("ShoppingCart", "cleanup_every_time");
                 if ($cleanUpEveryTime) {
                     $obj = new CartCleanupTask();
                     $obj->runSilently();
                 }
                 //create new order
                 $this->order = new Order();
                 if ($member) {
                     $this->order->MemberID = $member->ID;
                 }
                 $this->order->write();
             }
             Session::set($sessionVariableName, intval($this->order->ID));
         }
         //member just logged in and is not associated with order yet
         //if you are not logged in but the order belongs to a member then clear the cart.
         /***** THIS IS NOT CORRECT, BECAUSE YOU CAN CREATE AN ORDER FOR A USER AND NOT BE LOGGED IN!!! ***
         			elseif($this->order->MemberID && !$member) {
         				$this->clear();
         				return false;
         			}
         			*/
         if ($this->order && $this->order->exists() && $this->order->StatusID) {
             $this->order->calculateOrderAttributes();
         }
     }
     return $this->order;
 }
コード例 #6
0
ファイル: AppMock.php プロジェクト: kobabasu/rest-slim
 /**
  * bodyを設定 POST, PUTなど
  *
  * @param String $body // 投げるJSON
  * @return void
  */
 protected function setRequestBody($body)
 {
     $this->body->write($body);
     $this->body->rewind();
 }
コード例 #7
0
ファイル: DI.php プロジェクト: antoligy/Framework
 /**
  * Caches the compiled container
  *
  * @return DI
  * @author Dan Cox
  */
 public function cache()
 {
     $dump = new PhpDumper(static::$container);
     $this->cache->write($dump->dump(['class' => $this->cache_class, 'namespace' => $this->cache_namespace]), static::$container->getResources());
     return $this;
 }
コード例 #8
0
 /**
  * @param  SplFileInfo $file
  * @param  string      $reg_exp
  * @param  Object      $output
  * 
  * @return array
  */
 public function parse(SplFileInfo $file, $reg_exp, $output)
 {
     $parsed = array();
     $f = $file->openFile();
     while (!$f->eof()) {
         $line = $f->current();
         if (preg_match($reg_exp, $line, $data)) {
             $parsed[] = $data;
         } elseif ($output) {
             $output->write($line);
         }
         $f->next();
     }
     return $parsed;
 }
コード例 #9
0
 /**
  * Gets or creates the current order.
  * Based on the session ONLY!
  * IMPORTANT FUNCTION!
  * @todo - does this need to be public????
  * @return void
  */
 public function currentOrder($recurseCount = 0)
 {
     if (!$this->order) {
         $sessionVariableName = $this->sessionVariableName("OrderID");
         $orderIDFromSession = intval(Session::get($sessionVariableName));
         if ($orderIDFromSession > 0) {
             $this->order = Order::get()->byID($orderIDFromSession);
         }
         $member = Member::currentUser();
         if ($this->order) {
             //first reason to set to null: it is already submitted
             if ($this->order->IsSubmitted()) {
                 $this->order = null;
             } elseif (!$this->order->canView()) {
                 $this->order = null;
             } elseif ($member && $member->exists()) {
                 if ($this->order->MemberID != $member->ID) {
                     $updateMember = false;
                     if (!$this->order->MemberID) {
                         $updateMember = true;
                     }
                     if (!$member->IsShopAdmin()) {
                         $updateMember = true;
                     }
                     if ($updateMember) {
                         $this->order->MemberID = $member->ID;
                         $this->order->write();
                     }
                 }
                 //IF current order has nothing in it AND the member already has an order: use the old one first
                 //first, lets check if the current order is worthwhile keeping
                 if ($this->order->StatusID || $this->order->TotalItems()) {
                     //do NOTHING!
                 } else {
                     $firstStep = OrderStep::get()->First();
                     //we assume the first step always exists.
                     //TODO: what sort order?
                     $count = 0;
                     while ($firstStep && ($previousOrderFromMember = Order::get()->where("\r\n\t\t\t\t\t\t\t\t\t\"MemberID\" = " . $member->ID . "\r\n\t\t\t\t\t\t\t\t\tAND (\"StatusID\" = " . $firstStep->ID . " OR \"StatusID\" = 0)\r\n\t\t\t\t\t\t\t\t\tAND \"Order\".\"ID\" <> " . $this->order->ID)->First())) {
                         //arbritary 12 attempts ...
                         if ($count > 12) {
                             break;
                         }
                         $count++;
                         if ($previousOrderFromMember && $previousOrderFromMember->canView()) {
                             if ($previousOrderFromMember->StatusID || $previousOrderFromMember->TotalItems()) {
                                 $this->order->delete();
                                 $this->order = $previousOrderFromMember;
                                 break;
                             } else {
                                 $previousOrderFromMember->delete();
                             }
                         }
                     }
                 }
             }
         }
         if (!$this->order) {
             if ($member) {
                 $firstStep = OrderStep::get()->First();
                 if ($firstStep) {
                     $previousOrderFromMember = Order::get()->filter(array("MemberID" => $member->ID, "StatusID" => array($firstStep->ID, 0)))->First();
                     if ($previousOrderFromMember) {
                         if ($previousOrderFromMember->canView()) {
                             $this->order = $previousOrderFromMember;
                         }
                     }
                 }
             }
             if ($this->order && !$this->order->exists()) {
                 $this->order = null;
             }
             if (!$this->order) {
                 //here we cleanup old orders, because they should be
                 //cleaned at the same rate that they are created...
                 if (EcommerceConfig::get("ShoppingCart", "cleanup_every_time")) {
                     $cartCleanupTask = EcommerceTaskCartCleanup::create();
                     $cartCleanupTask->runSilently();
                 }
                 //create new order
                 $this->order = Order::create();
                 if ($member) {
                     $this->order->MemberID = $member->ID;
                 }
                 $this->order->write();
             }
             Session::set($sessionVariableName, intval($this->order->ID));
         } elseif ($this->order->MemberID && !$member) {
             $this->clear();
             $this->order = null;
         }
         if ($this->order && $this->order->exists()) {
             $this->order->calculateOrderAttributes($force = false);
         }
         if ($this->order && !$this->order->SessionID) {
             $this->order->SessionID = session_id();
             $this->order->write();
         }
     }
     //just in case ...
     if (!$this->order && $recurseCount < 3) {
         $recurseCount++;
         return $this->currentOrder();
     }
     return $this->order;
 }