/** * Open the connection * * @return static * * @throws ConnectionException */ public function connect() { if ($this->_client === null) { $remainingAttempts = (int) $this->_config()->getItem('connect_attempts', 1); while ($remainingAttempts > 0) { $remainingAttempts--; $exception = null; try { if (empty($this->_availableHosts)) { $this->_availableHosts = ValueAs::arr($this->_config()->getItem('hosts', 'localhost')); $this->_availableHostCount = count($this->_availableHosts); if ($this->_availableHostCount < 1) { throw new ConnectionException('Could not find any configured hosts'); } } shuffle($this->_availableHosts); $host = reset($this->_availableHosts); $this->_socket = new DalSocket($host, (int) $this->_config()->getItem('port', 9160), ValueAs::bool($this->_config()->getItem('persist', false))); $this->_socket->setConnectTimeout((int) $this->_config()->getItem('connect_timeout', 1000)); $this->_socket->setRecvTimeout((int) $this->_config()->getItem('receive_timeout', 1000)); $this->_socket->setSendTimeout((int) $this->_config()->getItem('send_timeout', 1000)); $this->_transport = new TFramedTransport($this->_socket); $this->_protocol = new TBinaryProtocolAccelerated($this->_transport); $this->_client = new CassandraClient($this->_protocol); $this->_transport->open(); $this->_connected = true; $this->_clearStmtCache(); $username = $this->_config()->getItem('username'); // @codeCoverageIgnoreStart if ($username) { $this->_client->login(new AuthenticationRequest(['credentials' => ['username' => $username, 'password' => $this->_config()->getItem('password', '')]])); } //@codeCoverageIgnoreEnd $this->_switchDatabase(null, !$this->_socket->isPersistent()); } catch (TException $e) { $exception = $e; } catch (CqlException $e) { $exception = $e; } if ($exception) { $this->_removeCurrentHost(); $this->disconnect(); if ($remainingAttempts < 1) { if (!$exception instanceof CqlException) { $exception = CqlException::from($exception); } throw new ConnectionException('Failed to connect: ' . $exception->getMessage(), $exception->getCode(), $exception->getPrevious()); } } else { break; } } } return $this; }
public function setFlag($name, $value = true) { if (empty($this->_customerFid)) { throw new \RuntimeException("You cannot set a flag before setting a customer fid"); } $payload = new SetPropertyValuePayload(); $payload->fid = $this->_customerFid; $payload->property = $name; $payload->value = ValueAs::bool($value); $this->_processRequest($this->_getPropertyEndpoint()->setFlag($payload)); return $this; }
/** * Open the connection * * @return static * * @throws ConnectionException */ public function connect() { $cfg = $this->_config(); $this->_connection = $this->_newConnection(); $servers = ValueAs::arr($cfg->getItem('servers', 'localhost')); foreach ($servers as $alias => $server) { $port = (int) $cfg->getItem($alias . '.port', $cfg->getItem('port', 11211)); $persist = ValueAs::bool($cfg->getItem($alias . '.persist', $cfg->getItem('persist', true))); $weight = (int) $cfg->getItem($alias . '.weight', $cfg->getItem('weight', 1)); $timeout = (int) $cfg->getItem($alias . '.timeout', $cfg->getItem('timeout', 1)); $this->_addserver($server, $port, $persist, $weight, $timeout); } return $this; }
public function getContent() { $data = parent::getContent(); //Return the raw content if minification has been disabled if (!ValueAs::bool($this->getOption('minify', true))) { return $data; } //Do not minify scripts containing the @do-not-minify if (strpos($data, '@' . 'do-not-minify') !== false) { return $data; } try { return Minifier::minify($data); } catch (\Exception $e) { return $data; } }
/** * @inheritdoc * * @param InputInterface $input * @param OutputInterface $output * * @return int|mixed|null */ protected function execute(InputInterface $input, OutputInterface $output) { if (ValueAs::bool($this->showfig)) { $output->write(Figlet::create('PHP WEB', 'ivrit')); $output->write(Figlet::create('SERVER', 'ivrit')); } $output->writeln(""); $output->write("\tStarting on "); $output->write("http://"); $output->write($this->host == '0.0.0.0' ? 'localhost' : $this->host); $output->write(':' . $this->port); $output->writeLn(""); $projectRoot = trim($this->getCubex()->getProjectRoot()); $projectRoot = $projectRoot ? '"' . $projectRoot . '"' : ''; $command = ["php -S {$this->host}:{$this->port} -t"]; $command[] = $projectRoot; $command[] = trim($this->router); $command = implode(' ', array_filter($command)); $output->writeln(["", "\tRaw Command: {$command}", ""]); return $this->runCommand($command); }
public function getContent() { $data = parent::getContent(); //Return the raw content if minification has been disabled if (!ValueAs::bool($this->getOption('minify', true))) { return $data; } //Do not minify scripts containing the @do-not-minify if (strpos($data, '@' . 'do-not-minify') !== false) { return $data; } // Remove comments. $data = preg_replace('@/\\*.*?\\*/@s', '', $data); // Remove whitespace around symbols. $data = preg_replace('@\\s*([{}:;,])\\s*@', '\\1', $data); // Remove unnecessary semicolons. $data = preg_replace('@;}@', '}', $data); // Replace #rrggbb with #rgb when possible. $data = preg_replace('@#([a-f0-9])\\1([a-f0-9])\\2([a-f0-9])\\3@i', '#\\1\\2\\3', $data); return trim($data); }
public function repairValue($tag, $property, $value, $options) { switch (strtolower($tag)) { case 'bool': $validBools = ['true', '1', 1, true, 'false', '0', 0, false]; if (in_array($value, $validBools)) { $value = ValueAs::bool($value); } break; case 'int': if (strlen((int) $value) == strlen($value)) { $value = (int) $value; } break; case 'float': if ((double) $value == strlen($value)) { $value = (double) $value; } break; } $this->_payload->{$property} = $value; }
/** * @param bool $bool * * @return $this */ public function showAutoSubmitButton($bool) { $this->_showAutoSubmitButton = ValueAs::bool($bool); return $this; }
/** * @return IAuthedUser */ public function getAuthedUser() { if ($this->_authedUser !== null) { return $this->_authedUser; } //Check cookie $cookieUser = $this->getCookieUser(false); if ($cookieUser !== null) { $this->_authedUser = $cookieUser; return $this->_authedUser; } //Check auth provider retrieve $serviceUser = $this->_authProvider->retrieveUser(); if ($serviceUser !== null) { $this->_authedUser = $serviceUser; //Set the login cookie when retrieved the user from the auth provider //Defaulted to on for speed, but can be disabled within the config if (ValueAs::bool($this->getCubex()->getConfiguration()->getItem('auth', 'cookie_retriever'), true)) { $this->_setLoginCookie($serviceUser); } } return $this->_authedUser; }