sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1
value |
|---|---|---|
public function FacebookShareLink()
{
if (!$this->owner->hasMethod('AbsoluteLink')) {
return false;
}
$pageURL = rawurlencode($this->owner->AbsoluteLink());
return ($pageURL) ? "https://www.facebook.com/sharer/sharer.php?u=$pageURL" : false;
} | Generate a URL to share this content on Facebook.
@return string|false | entailment |
public function TwitterShareLink()
{
if (!$this->owner->hasMethod('AbsoluteLink')) {
return false;
}
$pageURL = rawurlencode($this->owner->AbsoluteLink());
$text = rawurlencode($this->owner->getOGTitle());
return ($pageURL) ? "https://twitter.com/intent/tweet?tex... | Generate a URL to share this content on Twitter
Specs: https://dev.twitter.com/web/tweet-button/web-intent.
@return string|false | entailment |
public function GooglePlusShareLink()
{
if (!$this->owner->hasMethod('AbsoluteLink')) {
return false;
}
$pageURL = rawurlencode($this->owner->AbsoluteLink());
return ($pageURL) ? "https://plus.google.com/share?url=$pageURL" : false;
} | Generate a URL to share this content on Google+
Specs: https://developers.google.com/+/web/snippet/article-rendering.
@return string|false | entailment |
public function PinterestShareLink()
{
$pinImage = ($this->owner->hasMethod('getPinterestImage')) ? $this->owner->getPinterestImage() : $this->owner->getOGImage();
if ($pinImage) {
// OGImage may be an Image object or an absolute URL
$imageURL = rawurlencode((is_string($pinIm... | Generate a URL to share this content on Pinterest
Specs: https://developers.pinterest.com/pin_it/.
@return string|false | entailment |
public function LinkedInShareLink()
{
if (!$this->owner->hasMethod('AbsoluteLink')) {
return false;
}
$pageURL = rawurlencode($this->owner->AbsoluteLink());
$title = rawurlencode($this->owner->getOGTitle());
$description = rawurlencode($this->owner->getOGDescripti... | Generate a URL to share this content on LinkedIn
specs: https://developer.linkedin.com/docs/share-on-linkedin
@return string|string | entailment |
public function EmailShareLink()
{
if (!$this->owner->hasMethod('AbsoluteLink')) {
return false;
}
$pageURL = $this->owner->AbsoluteLink();
$subject = rawurlencode(_t('JonoM\ShareCare\ShareCare.EmailSubject', 'Thought you might like this'));
$body = rawurlencode(_... | Generate a 'mailto' URL to share this content via Email.
@return string|false | entailment |
public function getTwitterMetaTags()
{
$title = htmlspecialchars($this->owner->getOGTitle());
$description = htmlspecialchars($this->owner->getOGDescription());
$tMeta = "\n<meta name=\"twitter:title\" content=\"$title\">"
. "\n<meta name=\"twitter:description\" content=\"$descri... | Generate meta tag markup for Twitter Cards
Specs: https://dev.twitter.com/cards/types/summary-large-image.
@return string | entailment |
public function build(InvokeSpec $call): string
{
$response = [];
$units = $call->getUnits();
foreach ($units as $invoke) {
/** @var Invoke $invoke */
$invoke = $this->preBuild($invoke);
$response[] = [
'jsonrpc' => '2.0',
... | @param InvokeSpec $call
@return string | entailment |
private function preBuild(AbstractInvoke $invoke): AbstractInvoke
{
$result = $this->preBuild->handle(new BuilderContainer($this, $invoke));
if ($result instanceof BuilderContainer) {
return $result->getInvoke();
}
throw new \RuntimeException();
} | @param AbstractInvoke $invoke
@return AbstractInvoke | entailment |
public function generateScreenTopResolution($VisitorsID,$limit=20)
{
$arrScreenStatCount = false;
$this->TemplatePartial = new \BackendTemplate('mod_visitors_be_stat_partial_screentopresolution');
$objScreenStatCount = \Database::getInstance()
->prep... | //////////////////////////////////////////////////////////// | entailment |
public function beforeTraverse(array $nodes) : array
{
// quick fix - if the list is empty, replace it it
if (! $nodes) {
return (new ParserFactory())
->create(ParserFactory::PREFER_PHP7)
->parse(file_get_contents($this->reflectedClass->getFileName()));
... | {@inheritDoc}
@param array $nodes
@return \PhpParser\Node[] | entailment |
public function request(string $request): string
{
$request = $this->preRequest($request);
return $this->send($request);
} | Execute request
@param string $request
@return string | entailment |
private function preRequest(string $request): string
{
$result = $this->preRequest->handle(new TransportContainer($this, $request));
if ($result instanceof TransportContainer) {
return $result->getRequest();
}
throw new \RuntimeException();
} | @param string $request
@return string | entailment |
public function getUserClassName(string $className) : string
{
if (false === $position = strrpos($className, $this->generatedClassMarker)) {
return $className;
}
return substr(
$className,
$this->generatedClassMarkerLength + $position,
strrpos... | {@inheritDoc} | entailment |
public function getGeneratedClassName(string $className, array $options = array()) : string
{
return $this->generatedClassesNamespace
. $this->generatedClassMarker
. $this->getUserClassName($className)
. '\\' . $this->parameterEncoder->encodeParameters($options);
} | {@inheritDoc} | entailment |
public static function logMessage($strMessage, $strLog=null)
{
if ($strLog === null)
{
$strLog = 'prod-' . date('Y-m-d') . '.log';
}
else
{
$strLog = 'prod-' . date('Y-m-d') . '-' . $strLog . '.log';
}
$strLogsDir = null;
... | Wrapper for old log_message
@param string $strMessage
@param string $strLogg | entailment |
public static function useSocks5($host, $port = 1080, $user = null, $pass = null)
{
if ($host === null) {
self::$_socks5 = [];
} else {
self::$_socks5 = ['conn' => 'tcp://' . $host . ':' . $port];
if ($user !== null && $pass !== null) {
self::$_soc... | Set socks5 proxy server
@param string $host proxy server address, passed null to disable
@param int $port proxy server port, default to 1080
@param string $user authentication username
@param string $pass authentication password | entailment |
public static function connect($conn, $arg = null)
{
$obj = null;
if (!isset(self::$_objs[$conn])) {
self::$_objs[$conn] = [];
}
foreach (self::$_objs[$conn] as $tmp) {
if (!($tmp->flag & self::FLAG_BUSY)) {
Client::debug('reuse conn \'', $tmp-... | Create connection, with built-in pool.
@param string $conn connection string, like `protocal://host:port`.
@param mixed $arg external argument, fetched by `[[getExArg()]]`
@return static the connection object, null if it reaches the upper limit of concurrent, or false on failure. | entailment |
public static function findBySock($sock)
{
$sock = strval($sock);
return isset(self::$_refs[$sock]) ? self::$_refs[$sock] : null;
} | Find connection object by socket, used after stream_select()
@param resource $sock
@return Connection the connection object or null if not found. | entailment |
public function close($realClose = false)
{
$this->arg = null;
$this->flag &= ~self::FLAG_BUSY;
if ($realClose === true) {
Client::debug('close conn \'', $this->conn, '\': ', $this->sock);
$this->flag &= ~self::FLAG_OPENED;
@fclose($this->sock);
... | Close the connection
@param boolean $realClose whether to shutdown the connection, default is added to the pool for next request. | entailment |
public function addWriteData($buf)
{
if ($this->outBuf === null) {
$this->outBuf = $buf;
} else {
$this->outBuf .= $buf;
}
} | Append writing cache
@param $buf string data content. | entailment |
public function write($buf = null)
{
if ($buf === null) {
if ($this->proxyState > 0) {
return $this->proxyWrite();
}
$len = 0;
if ($this->hasDataToWrite()) {
$buf = $this->outLen > 0 ? substr($this->outBuf, $this->outLen) : $thi... | Write data to socket
@param string $buf the string to be written, passing null to flush cache.
@return mixed the number of bytes were written, 0 if the buffer is full, or false on error. | entailment |
public function getLine()
{
$line = @stream_get_line($this->sock, 2048, "\n");
if ($line === '' || $line === false) {
$line = $this->ioEmptyError() ? false : null;
} else {
$line = rtrim($line, "\r");
}
$this->ioFlagReset();
return $line;
} | Read one line (not contains \r\n at the end)
@return mixed line string, null when has not data, or false on error. | entailment |
public function read($size = 8192)
{
$buf = @fread($this->sock, $size);
if ($buf === '' || $buf === false) {
$buf = $this->ioEmptyError() ? false : null;
}
$this->ioFlagReset();
return $buf;
} | Read data from socket
@param int $size the max number of bytes to be read.
@return mixed the read string, null when has not data, or false on error. | entailment |
public function proxyRead()
{
$proxyState = $this->proxyState;
Client::debug('proxy readState: ', $proxyState);
if ($proxyState === 2) {
$buf = $this->read(2);
if ($buf === "\x05\x00") {
$this->proxyState = 5;
} elseif ($buf === "\x05\x02")... | Read data for proxy communication | entailment |
public function proxyWrite()
{
Client::debug('proxy writeState: ', $this->proxyState);
if ($this->proxyState === 1) {
$buf = isset(self::$_socks5['user']) ? "\x05\x01\x02" : "\x05\x01\x00";
$this->proxyState++;
return $this->write($buf);
} elseif ($this->p... | Write data for proxy communication
@return mixed | entailment |
public function generateNewsVisitHitTop($VisitorsID, $limit = 10, $parse = true)
{
$arrNewsStatCount = false;
//News Tables exists?
if (true === $this->getNewstableexists())
{
$objNewsStatCount = \Database::getInstance()
->prepare("SEL... | //////////////////////////////////////////////////////////// | entailment |
public function enterNode(Node $node)
{
if ($node instanceof Namespace_) {
$this->currentNamespace = $node;
return $node;
}
return null;
} | @param \PhpParser\Node $node
@return \PhpParser\Node\Stmt\Namespace_|null | entailment |
public function leaveNode(Node $node)
{
if ($node instanceof Namespace_) {
$this->currentNamespace = null;
}
if ($node instanceof Class_) {
$namespace = ($this->currentNamespace && is_array($this->currentNamespace->name->parts))
? implode('\\', $this-... | {@inheritDoc}
When leaving a node that is a class, replaces it with a modified version that extends the
given parent class
@todo can be abstracted away into a visitor that allows to modify the node via a callback
@param \PhpParser\Node $node
@return \PhpParser\Node\Stmt\Class_|null | entailment |
protected function newBaseQueryBuilder()
{
$conn = $this->getConnection();
$grammar = $conn->getQueryGrammar();
return new QueryCacheBuilder($this->queryCache(), $conn, $grammar, $conn->getPostProcessor());
} | Overrides the default QueryBuilder to inject the Cache methods.
@return QueryCacheBuilder | entailment |
public function finishSave(array $options)
{
if ($this->getCacheBusting()) {
$this->queryCache()->flush($this->getTable());
}
parent::finishSave($options);
} | Flushes the cache on insert/update.
@param array $options
@return void | entailment |
public function delete()
{
if ($this->getCacheBusting()) {
$this->queryCache()->flush($this->getTable());
}
return parent::delete();
} | Flushes the cache on deletes.
@return bool|null | entailment |
public function invoke($object, string $method, array $parameters)
{
$handler = $object;
$reflection = new \ReflectionMethod($handler, $method);
if ($reflection->getNumberOfRequiredParameters() > count($parameters)) {
throw new InvalidParamsException('Expected ' . $reflection... | @param mixed $object
@param string $method
@param array $parameters
@return mixed | entailment |
private function prepareActualParameters(array $formalParameters, array $parameters): array
{
$result = [];
// Handle named parameters
if ($this->isNamedArray($parameters)) {
foreach ($formalParameters as $formalParameter) {
/** @var \ReflectionParameter $formal... | @param \ReflectionParameter[] $formalParameters Formal parameters
@param array $parameters Parameters from request (raw)
@return array | entailment |
private function matchType(string $formalType, $value)
{
// Parameter without type-hinting returns as is
if ($formalType === '') {
return $value;
}
if ($this->isType($formalType, $value)) {
return $value;
}
throw new InvalidParamsException('T... | @param string $formalType
@param mixed $value
@return mixed | entailment |
private function toObject(string $formalClass, $value)
{
if ($this->typeAdapter->isClassRegistered($formalClass)) {
try {
return $this->typeAdapter->toObject($value);
} catch (TypeCastException $exception) {
throw new InvalidParamsException('Class cast... | @param string $formalClass
@param mixed $value
@return mixed | entailment |
private function isType(string $type, $value)
{
switch ($type) {
case 'bool':
return is_bool($value);
case 'int':
return is_int($value);
case 'float':
return is_float($value) || is_int($value);
case 'string':
... | @param string $type
@param $value
@return bool | entailment |
private function castResult($result)
{
try {
$result = $this->typeAdapter->toArray($result);
} catch (TypeCastException $exception) {
return $result;
}
return $result;
} | @param $result
@return mixed | entailment |
public function replaceInsertTagsVisitors($strTag)
{
$arrTag = StringUtil::trimsplit('::', $strTag);
if ($arrTag[0] != 'visitors')
{
if ($arrTag[0] != 'cache_visitors')
{
return false; // nicht für uns
}
}
\System::loadLanguageFile('tl_visitors');
if (isset($arrTag[1]))
{
$visitors... | replaceInsertTags
From TL 2.8 you can use prefix "cache_". Thus the InserTag will be not cached. (when "cache" is enabled)
visitors::katid::name - VisitorsName
visitors::katid::online - VisitorsOnlineCount
visitors::katid::start - VisitorsStartDate
visitors::katid::totalvisit - TotalVisitCount
visitors::katid:... | entailment |
protected function visitorCountUpdate($vid, $BlockTime, $visitors_category_id, $BackendUser = false)
{
$ModuleVisitorChecks = new ModuleVisitorChecks($BackendUser);
if (!isset($GLOBALS['TL_CONFIG']['mod_visitors_bot_check']) || $GLOBALS['TL_CONFIG']['mod_visitors_bot_check'] !== false)
{
if ($ModuleVisitorCh... | Insert/Update Counter | entailment |
protected function visitorGetPageObj()
{
$objPage = null;
$pageId = null;
$pageId = $this->getPageIdFromUrl(); // Alias, not ID :-(
// Load a website root page object if there is no page ID
if ($pageId === null)
{
$pageId = $this->visitorGetRootPageFromUrl();
}
M... | visitorCountUpdate | entailment |
protected function visitorCheckReferrer($vid)
{
if ($this->_HitCounted === true)
{
if ($this->_PF === false)
{
$ModuleVisitorReferrer = new ModuleVisitorReferrer();
$ModuleVisitorReferrer->checkReferrer();
$ReferrerDNS = $ModuleVisitorReferrer->getReferrerDNS();
$ReferrerFull= $ModuleVisito... | Check for Referrer
@param integer $vid Visitors ID | entailment |
protected function visitorSetDebugSettings($visitors_category_id)
{
$GLOBALS['visitors']['debug']['tag'] = false;
$GLOBALS['visitors']['debug']['checks'] = false;
$GLOBALS['visitors']['debug']['referrer'] = false;
$GLOBALS['visitors']['debug']['searchengine'] = false;
... | visitorCheckReferrer | entailment |
protected function visitorGetPageType($objPage)
{
$PageId = $objPage->id;
//Return:
//0 = reale Seite / Reader ohne Parameter - Auflistung der News/FAQs
//1 = Nachrichten/News
//2 = FAQ
//403 = Forbidden
$page_type = self::PAGE_TYPE_NORMAL;
if ($objPage->protected... | Get Page-Type
@param integer $objPage
@return integer 0 = reale Seite, 1 = News, 2 = FAQ, 403 = Forbidden | entailment |
protected function visitorGetPageIdByType($PageId,$PageType,$PageAlias)
{
if ($PageType == self::PAGE_TYPE_NORMAL)
{
ModuleVisitorLog::writeLog(__METHOD__ , __LINE__ , 'PageIdNormal: '. $PageId);
return $PageId;
}
if ($PageType == self::PAGE_TYPE_FORBIDDEN)
{
//P... | Get Page-ID by Page-Type
@param integer $PageId
@param integer $PageType
@param string $PageAlias
@return integer | entailment |
protected function isContao45()
{
$packages = \System::getContainer()->getParameter('kernel.packages');
$coreVersion = $packages['contao/core-bundle']; //a.b.c
if ( version_compare($coreVersion, '4.5.0', '>=') )
{
ModuleVisitorLog::writeLog( __METHOD__ , __LINE__ , ': True' );
ret... | Check if contao/cor-bundle >= 4.5.0
@return boolean | entailment |
public function setHeader($key, $value = null, $toLower = true)
{
if (is_array($key)) {
foreach ($key as $k => $v) {
$this->setHeader($k, $v);
}
} else {
if ($toLower === true) {
$key = strtolower($key);
}
if... | Set http header or headers
@param mixed $key string key or key-value pairs to set multiple headers.
@param string $value the header value when key is string, set null to remove header.
@param boolean $toLower convert key to lowercase | entailment |
public function addHeader($key, $value = null, $toLower = true)
{
if (is_array($key)) {
foreach ($key as $k => $v) {
$this->addHeader($k, $v);
}
} else {
if ($value !== null) {
if ($toLower === true) {
$key = str... | Add http header or headers
@param mixed $key string key or key-value pairs to be added.
@param string $value the header value when key is string.
@param boolean $toLower convert key to lowercase | entailment |
public function getHeader($key = null, $toLower = true)
{
if ($key === null) {
return $this->_headers;
}
if ($toLower === true) {
$key = strtolower($key);
}
return isset($this->_headers[$key]) ? $this->_headers[$key] : null;
} | Get a http header or all http headers
@param mixed $key the header key to be got, or null to get all headers
@param boolean $toLower convert key to lowercase
@return array|string the header value, or headers array when key is null. | entailment |
public function hasHeader($key, $toLower = true)
{
if ($toLower === true) {
$key = strtolower($key);
}
return isset($this->_headers[$key]);
} | Check HTTP header is set or not
@param string $key the header key to be check, not case sensitive
@param boolean $toLower convert key to lowercase
@return boolean if there is http header with the name. | entailment |
public function setRawCookie($key, $value, $expires = null, $domain = '-', $path = '/')
{
$domain = strtolower($domain);
if (substr($domain, 0, 1) === '.') {
$domain = substr($domain, 1);
}
if (!isset($this->_cookies[$domain])) {
$this->_cookies[$domain] = [];... | Set a raw cookie
@param string $key cookie name
@param string $value cookie value
@param integer $expires cookie will be expired after this timestamp.
@param string $domain cookie domain
@param string $path cookie path | entailment |
public function clearCookie($domain = '-', $path = null)
{
if ($domain === null) {
$this->_cookies = [];
} else {
$domain = strtolower($domain);
if ($path === null) {
unset($this->_cookies[$domain]);
} else {
if (isset($... | Clean all cookies
@param string $domain use null to clean all cookies, '-' to clean current cookies.
@param string $path | entailment |
public function getCookie($key, $domain = '-')
{
$domain = strtolower($domain);
if ($key === null) {
$cookies = [];
}
while (true) {
if (isset($this->_cookies[$domain])) {
foreach ($this->_cookies[$domain] as $path => $list) {
... | Get cookie value
@param string $key passing null to get all cookies
@param string $domain passing '-' to fetch from current session,
@return array|null|string | entailment |
public function applyCookie($req)
{
// fetch cookies
$host = $req->getHeader('host');
$path = $req->getUrlParam('path');
$cookies = $this->fetchCookieToSend($host, $path);
if ($this !== $req) {
$cookies = array_merge($cookies, $req->fetchCookieToSend($host, $path)... | Apply cookies for request
@param Request $req | entailment |
public function fetchCookieToSend($host, $path)
{
$now = time();
$host = strtolower($host);
$cookies = [];
$domains = ['-', $host];
while (strlen($host) > 1 && ($pos = strpos($host, '.', 1)) !== false) {
$host = substr($host, $pos + 1);
$domains[] = $h... | Fetch cookies to be sent
@param string $host
@param string $path
@return array | entailment |
public function run()
{
$logger = \System::getContainer()->get('monolog.logger.contao');
if (false === self::$_BackendUser && true === $this->isContao45())
{
$objTokenChecker = \System::getContainer()->get('contao.security.token_checker');
if ($objTokenChecker->hasBackendUser())
... | Run the controller
@return Response | entailment |
protected function visitorScreenSetResolutions()
{
$this->_SCREEN = array( "scrw" => (int)\Input::get('scrw'),
"scrh" => (int)\Input::get('scrh'),
"scriw" => (int)\Input::get('scriw'),
"scrih" => (int)\Input::get('sc... | Set $_SCREEN variable | entailment |
protected function visitorScreenCountUpdate($vid, $BlockTime, $visitors_category_id, $BackendUser = false)
{
ModuleVisitorLog::writeLog(__METHOD__ , __LINE__ , ': '.print_r($this->_SCREEN, true) );
$ModuleVisitorChecks = new ModuleVisitorChecks($BackendUser);
if ($ModuleVisitorChecks->checkBot() ... | Insert/Update Counter | entailment |
protected function visitorScreenSetDebugSettings($visitors_category_id)
{
$GLOBALS['visitors']['debug']['screenresolutioncount'] = false;
$objVisitors = \Database::getInstance()
->prepare("SELECT
visitors_expert_debug_screenresolut... | visitorScreenCountUpdate | entailment |
public function setName($name){
if(!is_string($name) && !is_numeric($name)){
throw new \Exception("Falscher Dateityp (".gettype($name).") number or string expected!");
}
$this->name = $name;
} | Diagrammname setzen | entailment |
public function setHeight($height){
if(!is_int($height)){
throw new \Exception("Falscher Dateityp (".gettype($height).") integer expected!");
}
$this->height = $height;
return true;
} | Höhe des Diagramms setzen | entailment |
public function setWidth($width){
if(!is_int($width)){
throw new \Exception("Falscher Dateityp (".gettype($width).") integer expected!");
}
$this->width = $width;
return true;
} | Breite des Diagramms setzen | entailment |
public function setMaxvalueHeight($maxvalue_height){
if(!is_int($maxvalue_height)){
throw new \Exception("Falscher Dateityp (".gettype($maxvalue_height).") integer expected!");
}
$this->maxvalue_height = $maxvalue_height;
return true;
} | Balkenhöhe des Maximalwertes setzen | entailment |
public function addX($x){
if(!is_numeric($x) && !is_string($x)){
throw new \Exception("Falscher Dateityp (".gettype($x).") number or string expected!");
}
$this->x[] = $x;
return true;
} | Fügt einen X-Wert hinzu | entailment |
public function addY($y){
if(!is_numeric($y)){
throw new \Exception("Falscher Dateityp (".gettype($y).") number expected!");
}
$this->y[] = $y;
return true;
} | Fügt einen Y-Wert hinzu | entailment |
public function addY2($y2){
if(!is_numeric($y2)){
throw new \Exception("Falscher Dateityp (".gettype($y2).") number expected!");
}
$this->y2[] = $y2;
return true;
} | Fügt einen Y2-Wert hinzu | entailment |
public static function createDefault(string $class): Rule
{
$rule = new Rule($class);
$reflection = new \ReflectionClass($class);
$properties = $reflection->getProperties();
foreach ($properties as $property) {
/** @var \ReflectionProperty $property */
$rule... | Create rule with one-to-one mapping
@param string $class
@return Rule | entailment |
public function assign(string $property, string $key)
{
$this->doAssign($property, $key);
return $this;
} | Simple property-key pair assigning
@param string $property Object property
@param string $key Map key
@return $this | entailment |
public function assignConstructor(string $property, string $key, callable $fx)
{
$this->doAssign($property, $key);
$this->constructors[$property] = $fx;
return $this;
} | Assign property constructor
@param string $property
@param string $key
@param callable $fx
@return $this | entailment |
public function assignSerializer(string $property, string $key, callable $fx)
{
$this->doAssign($property, $key);
$this->serializers[$property] = $fx;
return $this;
} | Assign property serializer
@param string $property
@param string $key
@param callable $fx
@return $this | entailment |
public function execute(): string
{
$calls = $this->requestParser->parse($this->requestProvider->getPayload());
$result = $this->processor->process($calls);
return $this->responseBuilder->build($result);
} | Run server
@return string | entailment |
public function encodeParameters(array $parameters) : string
{
return str_replace('+/=', '†‡•', base64_encode(serialize($parameters)));
} | Converts the given parameters into a set of characters that are safe to
use in a class name
@param array $parameters
@return string | entailment |
public function set(
$method = null,
$mount = null,
$path = null,
$handler = null,
string $info = null
) : object {
$this->mount = rtrim($mount, "/");
$this->path = $path;
$this->handler = $handler;
$this->info = $info;
$this->method =... | Set values for route.
@param string|array $method as request method to support
@param string $mount where to mount the path
@param string $path for this route
@param string|array|callable $handler for this path, callable or equal
@param string $info d... | entailment |
public function match(string $query, string $method = null)
{
$this->arguments = [];
$this->methodMatched = null;
$this->pathMatched = null;
$matcher = new RouteMatcher();
$res = $matcher->match(
$this->mount,
$this->path,
$this->getAbsolu... | Check if the route matches a query and request method.
@param string $query to match against
@param string $method as request method
@return boolean true if query matches the route | entailment |
public function handle(
string $path = null,
ContainerInterface $di = null
) {
if ($this->mount) {
// Remove the mount path to get base for controller
$len = strlen($this->mount);
if (substr($path, 0, $len) == $this->mount) {
$path = ltrim(... | Handle the action for the route.
@param string $path the matched path
@param ContainerInjectableInterface $di container with services
@return mixed | entailment |
public function getMatchedPath()
{
$path = $this->pathMatched;
if ($this->mount) {
$len = strlen($this->mount);
if (substr($path, 0, $len) == $this->mount) {
$path = ltrim(substr($path, $len), "/");
}
}
return $path;
} | Get the matched basename of the path, its the part without the mount
point.
@return string|null | entailment |
public function getAbsolutePath()
{
if (empty($this->mount) && is_null($this->path)) {
return null;
}
if (empty($this->mount)) {
return $this->path;
}
return $this->mount . "/" . $this->path;
} | Get the absolute $path by adding $mount.
@return string|null as absolute path for this route. | entailment |
public function getHandlerType(ContainerInterface $di = null) : string
{
$handler = new RouteHandler();
return $handler->getHandlerType($this->handler, $di);
} | Get the handler type as a informative string.
@param ContainerInjectableInterface $di container with services
@return string representing the handler. | entailment |
public function reset()
{
$this->status = 400;
$this->statusText = 'Bad Request';
$this->body = '';
$this->error = null;
$this->timeCost = 0;
$this->clearHeader();
$this->clearCookie();
} | Reset object | entailment |
public function redirect($url)
{
// has redirect from upstream
if (($this->status === 301 || $this->status === 302) && ($this->hasHeader('location'))) {
return;
}
// @fixme need a better solution
$this->numRedirected--;
$this->status = 302;
$this->... | Redirect to another url
This method can be used in request callback.
@param string $url target url to be redirected to. | entailment |
public function getJson()
{
if (stripos($this->getHeader('content-type'), '/json') !== false) {
return json_decode($this->body, true);
} else {
return false;
}
} | Get json response data
@return mixed | entailment |
public function publishSlides()
{
$slides = SlideImage::get();
$ct = 0;
foreach ($this->getSlides() as $slide) {
if ($slide->ShowSlide == 1) {
if (!$slide->Name) {
$slide->Name = "No Name";
}
$slide->writeToStage... | mark all ProductDetail records as ShowInMenus = 0. | entailment |
public function getConn()
{
if ($this->conn === null) {
$this->conn = Connection::connect($this->req->getUrlParam('conn'), $this);
if ($this->conn === false) {
$this->res->error = Connection::getLastError();
$this->finish();
} else {
... | Get connection
@return Connection the connection object, returns null if the connection fails or need to queue. | entailment |
public function finish($type = 'NORMAL')
{
$this->finished = true;
if ($type === 'BROKEN') {
$this->res->error = Connection::getLastError();
} else {
if ($type !== 'NORMAL') {
$this->res->error = ucfirst(strtolower($type));
}
}
... | Finish the processor
@param string $type finish type, supports: NORMAL, BROKEN, TIMEOUT | entailment |
public static function spawn($cmd, $cwd = null, LoggerInterface $logger = null)
{
return new self($cmd, $cwd, $logger);
} | Spawn a new instance of Expect for the given command.
You can optionally specify a working directory and a
PSR compatible logger to use.
@param string $cmd
@param string $cwd
@param LoggerInterface $logger
@return $this | entailment |
public function expect($output, $timeout = self::DEFAULT_TIMEOUT)
{
$this->steps[] = [self::EXPECT, $output, $timeout];
return $this;
} | Register a step to expect the given text to show up on stdout.
Expect will block and keep checking the stdout buffer until your expectation
shows up or the timeout is reached, whichever comes first.
@param string $output
@param int $timeout
@return $this | entailment |
public function send($input)
{
if (stripos(strrev($input), PHP_EOL) === false) {
$input = $input . PHP_EOL;
}
$this->steps[] = [self::SEND, $input];
return $this;
} | Register a step to send the given text on stdin.
A newline is added to each string to simulate pressing enter.
@param string $input
@return $this | entailment |
public function run()
{
$this->createProcess();
foreach ($this->steps as $step) {
if ($step[0] === self::EXPECT) {
$expectation = $step[1];
$timeout = $step[2];
$this->waitForExpectedResponse($expectation, $timeout);
} else... | Run the process and execute the registered steps.
The program will block until the steps are completed or a timeout occurs.
@return null
@throws \RuntimeException If the process can not be created.
@throws \Yuloh\Expect\Exceptions\ProcessTimeoutException if the process times out.
@throws \Yuloh\Expect\Exceptions\U... | entailment |
private function createProcess()
{
$descriptorSpec = [
['pipe', 'r'], // stdin
['pipe', 'w'], // stdout
['pipe', 'r'] // stderr
];
$this->process = proc_open($this->cmd, $descriptorSpec, $this->pipes, $this->cwd);
if (!is_resource($this->process... | Create the process.
@return null
@throws \RuntimeException If the process can not be created. | entailment |
private function closeProcess()
{
fclose($this->pipes[0]);
fclose($this->pipes[1]);
fclose($this->pipes[2]);
proc_close($this->process);
} | Close the process.
@return null | entailment |
private function waitForExpectedResponse($expectation, $timeout)
{
$response = null;
$lastLoggedResponse = null;
$buffer = '';
$start = time();
stream_set_blocking($this->pipes[1], false);
while (true) {
if (time() - $st... | Wait for the given response to show on stdout.
@param string $expectation The expected output. Will be glob matched.
@return null
@throws \Yuloh\Expect\Exceptions\ProcessTimeoutException if the process times out.
@throws \Yuloh\Expect\Exceptions\UnexpectedEOFException if an unexpected EOF is found.
@throws \Yuloh\Ex... | entailment |
private function isRunning()
{
if (!is_resource($this->process)) {
return false;
}
$status = proc_get_status($this->process);
return $status['running'];
} | Determine if the process is running.
@return boolean | entailment |
protected function reset()
{
ModuleVisitorLog::writeLog( __METHOD__ , __LINE__ , 'Referrer Raw: ' . $_SERVER['HTTP_REFERER'] );
//NEVER TRUST USER INPUT
if (function_exists('filter_var')) // Adjustment for hoster without the filter extension
{
$this->_http_referrer = isset($_SERVER['HTTP_RE... | Reset all properties | entailment |
protected function vhost()
{
$host = rtrim($_SERVER['HTTP_HOST']);
if (empty($host))
{
$host = $_SERVER['SERVER_NAME'];
}
$host = preg_replace('/[^A-Za-z0-9\[\]\.:-]/', '', $host);
if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
{
$xhost = preg_replace('/[^A-Za-z0-9\[\]\.:-]/', '', rtrim($_SERVE... | Return the current URL without path or query string or protocol
@return string | entailment |
public function generate(array $ast) : string
{
$code = parent::generate($ast);
if (! $this->canEval) {
$fileName = sys_get_temp_dir() . '/EvaluatingGeneratorStrategy.php.tmp.' . uniqid('', true);
file_put_contents($fileName, "<?php\n" . $code);
require $fileNam... | Evaluates the generated code before returning it
{@inheritDoc} | entailment |
public function setUrl($url)
{
$this->_rawUrl = $url;
if (strncasecmp($url, 'http://', 7) && strncasecmp($url, 'https://', 8) && isset($_SERVER['HTTP_HOST'])) {
if (substr($url, 0, 1) != '/') {
$url = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/'... | Set request URL
Relative url will be converted to full url by adding host and protocol.
@param string $url raw url | entailment |
public function getUrlParams()
{
if ($this->_urlParams === null) {
$pa = @parse_url($this->getUrl());
$pa['scheme'] = isset($pa['scheme']) ? strtolower($pa['scheme']) : 'http';
if ($pa['scheme'] !== 'http' && $pa['scheme'] !== 'https') {
return false;
... | Get url parameters
@return array the parameters parsed from URL, or false on error | entailment |
public function getUrlParam($key)
{
$pa = $this->getUrlParams();
return isset($pa[$key]) ? $pa[$key] : null;
} | Get url parameter by key
@param string $key parameter name
@return string the parameter value or null if non-exists. | entailment |
public function getBody()
{
$body = '';
if ($this->_method === 'POST' || $this->_method === 'PUT') {
if ($this->_body === null) {
$this->_body = $this->getPostBody();
}
$this->setHeader('content-length', strlen($this->_body));
$body = $... | Get http request body
Appending post fields and files.
@return string request body | entailment |
public function setBody($body)
{
$this->_body = $body;
$this->setHeader('content-length', $body === null ? null : strlen($body));
} | Set http request body
@param string $body content string. | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.