public function testProcessHostNoRedirect() { $site = CM_Site_Abstract::factory(); $request = new CM_Http_Request_Get('/mock5', ['host' => $site->getHost()]); $response = CM_Http_Response_Page::createFromRequest($request, $site, $this->getServiceManager()); $response->process(); $this->assertFalse(Functional\some($response->getHeaders(), function ($header) { return preg_match('/^Location:/', $header); })); }
/** * @param CM_Clockwork_Event $event * @throws CM_Exception */ public function registerEvent(CM_Clockwork_Event $event) { $eventName = $event->getName(); $duplicateEventName = \Functional\some($this->_events, function (CM_Clockwork_Event $event) use($eventName) { return $event->getName() == $eventName; }); if ($duplicateEventName) { throw new CM_Exception('Duplicate event-name', ['name' => $eventName]); } $this->_events[] = $event; }
/** * @return bool * @throws CM_Exception */ public function hasPartitions() { $blocks = explode("\n", CM_Util::exec('lsblk', ['-n', '-o', 'TYPE', $this->_getPathWithoutPartition()])); return \Functional\some($blocks, function ($block) { return $block === 'part'; }); }
/** * @param CM_Cli_Arguments $arguments * @throws CM_Exception * @return int */ public function run(CM_Cli_Arguments $arguments) { $method = new ReflectionMethod($this, 'configure'); $parameters = $arguments->extractMethodParameters($method); $method->invokeArgs($this, $parameters); try { $packageName = $arguments->getNumeric()->shift(); $methodName = $arguments->getNumeric()->shift(); if (!$packageName) { $this->_outputError($this->getHelp()); return 1; } if (!$methodName) { $this->_outputError($this->getHelp($packageName)); return 1; } $process = $this->_getProcess(); $command = $this->_getCommand($packageName, $methodName); if ($command->getSynchronized()) { $this->monitorSynchronizedCommands(); $this->_checkLock($command); $this->_lockCommand($command); $process->bind('exit', function () use($command) { $this->unlockCommand($command); }); } $transactionName = 'cm ' . $packageName . ' ' . $methodName; $streamInput = $this->_streamInput; $streamOutput = $this->_streamOutput; $streamError = $this->_streamError; $workload = $this->_getProcessWorkload($transactionName, $command, $arguments, $streamInput, $streamOutput, $streamError); $forks = max($this->_forks, 1); for ($i = 0; $i < $forks; $i++) { $process->fork($workload); } $resultList = $process->waitForChildren($command->getKeepalive()); if ($command->getSynchronized()) { $this->unlockCommand($command); } $failure = Functional\some($resultList, function (CM_Process_WorkloadResult $result) { return !$result->isSuccess(); }); if ($failure) { return 1; } return 0; } catch (CM_Cli_Exception_Internal $e) { $this->_outputError('ERROR: ' . $e->getMessage() . PHP_EOL); return 1; } }
/** * @param string $host * @param string $path * @return bool * @throws CM_Exception */ public function isUrlMatch($host, $path) { $matchList = [['host' => $this->getHost(), 'path' => $this->getPath()], ['host' => preg_replace('/^www\\./', '', $this->getHost()), 'path' => $this->getPath()]]; if ($this->getUrlCdn()) { $urlCdn = new CM_Http_UrlParser($this->getUrlCdn()); $matchList[] = ['host' => $urlCdn->getHost(), 'path' => $urlCdn->getPath()]; } $path = new Stringy\Stringy($path); return Functional\some($matchList, function ($match) use($host, $path) { return $host === $match['host'] && $path->startsWith($match['path']); }); }
/** * @param string $collection * @param array $index * @return bool */ public function hasIndex($collection, array $index) { $indexInfo = $this->getIndexInfo($collection); return \Functional\some($indexInfo, function ($indexInfo) use($index) { return array_keys($index) === array_keys($indexInfo['key']) && $index == $indexInfo['key']; }); }
public function testSetName() { $language = CMTest_TH::createLanguage(); $key = CM_Model_LanguageKey::create('foo'); $key->setName('bar'); $this->assertSame('bar', $key->getName()); $this->assertTrue(Functional\some($language->getTranslations()->getItems(), function ($translation) { return $translation['key'] === 'bar'; })); }