_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 33
8k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q266900
|
Tokenizer.getStatedClassInstanceToken
|
test
|
public function getStatedClassInstanceToken(LifeCyclableInterface $object): string
{
$statedClassName = \get_class($object);
|
php
|
{
"resource": ""
}
|
q266901
|
PEAR_REST_11.listCategory
|
test
|
function listCategory($base, $category, $info = false, $channel = false)
{
if ($info == false) {
$url = '%s'.'c/%s/packages.xml';
} else {
$url = '%s'.'c/%s/packagesinfo.xml';
}
$url = sprintf($url,
$base,
urlencode($category));
// gives '404 Not Found' error when category doesn't exist
$packagelist = $this->_rest->retrieveData($url, false, false, $channel);
if (PEAR::isError($packagelist)) {
return $packagelist;
}
if (!is_array($packagelist)) {
return array();
}
if ($info == false) {
if (!isset($packagelist['p'])) {
return array();
}
if (!is_array($packagelist['p']) ||
!isset($packagelist['p'][0])) { // only 1 pkg
$packagelist = array($packagelist['p']);
} else {
$packagelist = $packagelist['p'];
}
return $packagelist;
}
// info == true
if (!isset($packagelist['pi'])) {
return array();
}
if (!is_array($packagelist['pi']) ||
|
php
|
{
"resource": ""
}
|
q266902
|
PEAR_REST_11.betterStates
|
test
|
function betterStates($state, $include = false)
{
static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable');
$i = array_search($state, $states);
if ($i === false) {
return false;
|
php
|
{
"resource": ""
}
|
q266903
|
Executioner.compileCommand
|
test
|
private function compileCommand()
{
$command = '';
if ($this->sudo) {
$command = 'sudo ';
}
$command .= escapeshellcmd($this->applicationPath) . $this->generateArguments();
|
php
|
{
"resource": ""
}
|
q266904
|
Executioner.generateArguments
|
test
|
protected function generateArguments()
{
$arguments = '';
if (!$this->applicationArguments->isEmpty()) {
$arguments = ' ' .
|
php
|
{
"resource": ""
}
|
q266905
|
Executioner.executeProcess
|
test
|
private function executeProcess()
{
$command = $this->compileCommand();
exec($command, $result, $status);
if ($status > 0) {
|
php
|
{
"resource": ""
}
|
q266906
|
FileManager.save
|
test
|
private function save()
{
foreach ($this->stream as $key => $file) {
$layer = ucwords($key);
$namespace = Text::replace($this->namespace, '\\', '/');
$root = Text::replace("{$this->directory}/{$namespace}/{$layer}", '//', '/');
$success = true;
if (!Directory::exists($root)) {
$success = Directory::make($root);
}
if (!$success) {
|
php
|
{
"resource": ""
}
|
q266907
|
FileManager.replace
|
test
|
private function replace()
{
foreach ($this->stream as &$content) {
foreach ($this->replacements as $field) {
|
php
|
{
"resource": ""
}
|
q266908
|
NativeRouter.addRoute
|
test
|
public function addRoute(Route $route): void
{
// Verify the dispatch
$this->app->dispatcher()->verifyDispatch($route);
// Set the path to the validated cleaned path (/some/path)
$route->setPath($this->validatePath($route->getPath()));
|
php
|
{
"resource": ""
}
|
q266909
|
NativeRouter.get
|
test
|
public function get(Route $route): void
{
$route->setRequestMethods([RequestMethod::GET,
|
php
|
{
"resource": ""
}
|
q266910
|
NativeRouter.post
|
test
|
public function post(Route $route): void
{
$route->setRequestMethods([RequestMeth
|
php
|
{
"resource": ""
}
|
q266911
|
NativeRouter.put
|
test
|
public function put(Route $route): void
{
$route->setRequestMethods([RequestMeth
|
php
|
{
"resource": ""
}
|
q266912
|
NativeRouter.patch
|
test
|
public function patch(Route $route): void
{
$route->setRequestMethods([RequestMeth
|
php
|
{
"resource": ""
}
|
q266913
|
NativeRouter.delete
|
test
|
public function delete(Route $route): void
{
$route->setRequestMethods([RequestMeth
|
php
|
{
"resource": ""
}
|
q266914
|
NativeRouter.head
|
test
|
public function head(Route $route): void
{
$route->setRequestMethods([RequestMeth
|
php
|
{
"resource": ""
}
|
q266915
|
NativeRouter.route
|
test
|
public function route(string $name): Route
{
// If no route was found
if (! $this->routeIsset($name)) {
|
php
|
{
"resource": ""
}
|
q266916
|
NativeRouter.routeUrl
|
test
|
public function routeUrl(string $name, array $data = null, bool $absolute = null): string
{
// Get the matching route
$route = $this->route($name);
// Set the host to use if this is an absolute url
// or the config is set to always use absolute urls
// or the route is secure (needs https:// appended)
$host = $absolute
|| $this->app->config()['routing']['useAbsoluteUrls']
|| $route->isSecure()
? $this->routeHost($route)
: '';
// Get the path from the
|
php
|
{
"resource": ""
}
|
q266917
|
NativeRouter.requestRoute
|
test
|
public function requestRoute(Request $request): ? Route
{
$requestMethod = $request->getMethod();
// Decode the request uri
|
php
|
{
"resource": ""
}
|
q266918
|
NativeRouter.matchRoute
|
test
|
public function matchRoute(string $path, string $method = null): ? Route
{
// Validate the path
$path = $this->validatePath($path);
$method = $method ?? RequestMethod::GET;
|
php
|
{
"resource": ""
}
|
q266919
|
NativeRouter.isInternalUri
|
test
|
public function isInternalUri(string $uri): bool
{
// Replace the scheme if it exists
$uri = str_replace(['http://', 'https://'], '', $uri);
// Get the host of the uri
$host = (string) substr($uri, 0, strpos($uri, '/'));
// If the host does not match the current request uri's host
if ($host && $host !== $this->app->request()->getHttpHost()) {
// Return false immediately
return false;
}
// Get only the path (full string
|
php
|
{
"resource": ""
}
|
q266920
|
NativeRouter.dispatch
|
test
|
public function dispatch(Request $request): Response
{
// Check the returned route
if (null === $route = $this->requestRoute($request)) {
// If it was null throw a not found exception
throw new NotFoundHttpException();
}
// If the route is secure and the current request is not secure
if ($route->isSecure() && ! $request->isSecure()) {
// Throw the redirect to the secure path
return $this->app->redirect()->secure($request->getPath());
}
// Dispatch the route's before request handled middleware
$middlewareReturn = $this->routeRequestMiddleware($request, $route);
|
php
|
{
"resource": ""
}
|
q266921
|
NativeRouter.setup
|
test
|
public function setup(bool $force = false, bool $useCache = true): void
{
// If route's have already been setup, no need to do it again
if (self::$setup && ! $force) {
return;
}
self::$setup = true;
// If the application should use the routes cache file
if ($useCache && $this->app->config()['routing']['useCache']) {
$this->setupFromCache();
// Then return out of setup
return;
}
self::$collection = new RouteCollection();
// If annotations are enabled and routing should use annotations
if (
$this->app->config()['routing']['useAnnotations']
&& $this->app->config()['annotations']['enabled']
) {
//
|
php
|
{
"resource": ""
}
|
q266922
|
NativeRouter.setDynamicRoute
|
test
|
protected function setDynamicRoute(Route $route): void
{
// Parse the path
$parsedRoute = $this->app->pathParser()->parse($route->getPath());
// Set the properties
|
php
|
{
"resource": ""
}
|
q266923
|
NativeRouter.validateRouteUrl
|
test
|
protected function validateRouteUrl(string $path): string
{
// If the last character is not a slash and the config is set to
// ensure trailing slash
if (
$path[-1] !== '/'
|
php
|
{
"resource": ""
}
|
q266924
|
NativeRouter.matchStaticRoute
|
test
|
protected function matchStaticRoute(string $path, string $method): ? Route
{
$route = null;
// Let's check if the route is set in the static routes
if (self::$collection->issetStaticRoute($method, $path)) {
$route = $this->getMatchedStaticRoute($path, $method);
|
php
|
{
"resource": ""
}
|
q266925
|
NativeRouter.matchDynamicRoute
|
test
|
protected function matchDynamicRoute(string $path, string $method): ? Route
{
// The route to return (null by default)
$route = null;
// The dynamic routes
$dynamicRoutes = self::$collection->getDynamicRoutes($method);
// Attempt to find a match using dynamic routes that are set
foreach ($dynamicRoutes as $regex => $dynamicRoute) {
// If the preg match is successful, we've found our route!
/* @var array $matches */
if (preg_match($regex, $path, $matches)) {
|
php
|
{
"resource": ""
}
|
q266926
|
NativeRouter.getMatchedStaticRoute
|
test
|
protected function getMatchedStaticRoute(string $path, string $method): Route
|
php
|
{
"resource": ""
}
|
q266927
|
NativeRouter.getMatchedDynamicRoute
|
test
|
protected function getMatchedDynamicRoute(string $path, array $matches, string $method): Route
{
// Clone the route to avoid changing the one set in the master array
$dynamicRoute = clone self::$collection->dynamicRoute($method, $path);
// The first match is the path itself
unset($matches[0]);
// Iterate through the matches
foreach ($matches as $key => $match) {
// If there is no match (middle of regex optional group)
if (! $match) {
|
php
|
{
"resource": ""
}
|
q266928
|
NativeRouter.routeRequestMiddleware
|
test
|
protected function routeRequestMiddleware(Request $request, Route $route)
{
// If the route has no middleware
if (null === $route->getMiddleware()) {
// Return the request passed through
return $request;
|
php
|
{
"resource": ""
}
|
q266929
|
NativeRouter.routeResponseMiddleware
|
test
|
protected function routeResponseMiddleware(Request $request, Response $response, Route $route): void
{
// If the route has no middleware
if (null === $route->getMiddleware()) {
// Return the response passed through
return;
|
php
|
{
"resource": ""
}
|
q266930
|
NativeRouter.getResponseFromDispatch
|
test
|
protected function getResponseFromDispatch($dispatch): Response
{
// If the dispatch failed, 404
if (! $dispatch) {
$this->app->abort();
}
// If the dispatch is a Response then simply return it
if ($dispatch instanceof Response) {
return $dispatch;
}
// If the dispatch is a View, render it then wrap it in a new response
// and return it
if ($dispatch instanceof
|
php
|
{
"resource": ""
}
|
q266931
|
NativeRouter.setupFromCache
|
test
|
protected function setupFromCache(): void
{
// Set the application routes with said file
$cache = $this->app->config()['cache']['routing']
?? require $this->app->config()['routing']['cacheFilePath'];
self::$collection = unserialize(
base64_decode($cache['collection'], true),
|
php
|
{
"resource": ""
}
|
q266932
|
NativeRouter.setupAnnotatedRoutes
|
test
|
protected function setupAnnotatedRoutes(): void
{
/** @var RouteAnnotations $routeAnnotations */
$routeAnnotations = $this->app->container()->getSingleton(
RouteAnnotations::class
);
// Get all the annotated routes from the list of controllers
$routes = $routeAnnotations->getRoutes(
|
php
|
{
"resource": ""
}
|
q266933
|
Modal.renderHeader
|
test
|
protected function renderHeader()
{
$button = $this->renderCloseButton();
if ($button !== null) {
$this->header = $this->header . "\n" . $button;
}
if ($this->header !== null) {
Html::addCssClass($this->headerOptions, ['widget' => 'modal-header']);
|
php
|
{
"resource": ""
}
|
q266934
|
Modal.renderToggleButton
|
test
|
protected function renderToggleButton()
{
if (($toggleButton = $this->toggleButton) !== false) {
$tag = ArrayHelper::remove($toggleButton, 'tag', 'button');
$label = ArrayHelper::remove($toggleButton, 'label', 'Show');
if ($tag === 'button' && !isset($toggleButton['type'])) {
|
php
|
{
"resource": ""
}
|
q266935
|
GettextMessageSource.getGettextFile
|
test
|
protected function getGettextFile($messageFile)
{
if (isset($this->_gettextFiles[$messageFile])) {
return $this->_gettextFiles[$messageFile];
}
if (!is_file($messageFile)) {
return null;
}
if ($this->useMoFile) {
$gettextFile = new
|
php
|
{
"resource": ""
}
|
q266936
|
DQL.getQBResult
|
test
|
protected function getQBResult(Params $params, Query $query)
{
$paginated = new Paginator($query);
|
php
|
{
"resource": ""
}
|
q266937
|
DQL.addFilters
|
test
|
protected function addFilters(Params $params, QueryBuilder $qb)
{
|
php
|
{
"resource": ""
}
|
q266938
|
DQL.filterBySearch
|
test
|
protected function filterBySearch(Params $params, QueryBuilder $qb)
{
if ($query = $params->getWrapped('search')->get('value')) {
|
php
|
{
"resource": ""
}
|
q266939
|
DQL.searchFilter
|
test
|
protected function searchFilter(Params $params, QueryBuilder $qb, $search)
{
$qb->andWhere($this->alias('id').'
|
php
|
{
"resource": ""
}
|
q266940
|
DQL.addOrdering
|
test
|
protected function addOrdering(Params $params, QueryBuilder $qb)
{
$orderDir = "ASC";
if ($params->has('orderDir') && (strtoupper($params->get('orderDir')) == "DESC")) {
$orderDir = "DESC";
}
if
|
php
|
{
"resource": ""
}
|
q266941
|
DQL.addOffset
|
test
|
protected function addOffset(Params $params, QueryBuilder $qb)
{
if ($this->getOffset() &&
|
php
|
{
"resource": ""
}
|
q266942
|
DQL.addLimit
|
test
|
protected function addLimit(Params $params, QueryBuilder $qb)
{
if ($this->getLimit() &&
|
php
|
{
"resource": ""
}
|
q266943
|
DQL.find
|
test
|
public function find($id)
{
$params = Params::create(array($this->getIdParam() => $id, 'limit' => 1));
$qb = $this->getCustomizedQueryBuilder($params);
$results = $this->getQBResult($params, $this->queryHook($params, $qb));
if ($results->count() != 1) {
|
php
|
{
"resource": ""
}
|
q266944
|
DQL.safeJoin
|
test
|
public function safeJoin(QueryBuilder $qb, $property, $joinedAlias, $autoAlias = true)
{
if ($autoAlias) {
$property = $this->alias($property);
|
php
|
{
"resource": ""
}
|
q266945
|
DQL.getDataTablesSortColumn
|
test
|
protected function getDataTablesSortColumn(Params $params)
{
$column = $params->getWrapped('order')->getWrapped(0)->get('column', 0);
|
php
|
{
"resource": ""
}
|
q266946
|
DQL.orderByDataTablesParams
|
test
|
protected function orderByDataTablesParams(Params $params, QueryBuilder $qb)
{
$order = $this->getDataTablesSortOrder($params);
$sort = $this->getDataTablesSortColumn($params);
|
php
|
{
"resource": ""
}
|
q266947
|
PhoneValidator.isValid
|
test
|
public function isValid($value, Constraint $constraint)
{
if (empty($value)) {
return true;
}
|
php
|
{
"resource": ""
}
|
q266948
|
XML_Util.replaceEntities
|
test
|
function replaceEntities($string, $replaceEntities = XML_UTIL_ENTITIES_XML,
$encoding = 'ISO-8859-1')
{
switch ($replaceEntities) {
case XML_UTIL_ENTITIES_XML:
return strtr($string, array(
'&' => '&',
'>' => '>',
'<' => '<',
'"' => '"',
'\'' => ''' ));
break;
case XML_UTIL_ENTITIES_XML_REQUIRED:
|
php
|
{
"resource": ""
}
|
q266949
|
XML_Util.reverseEntities
|
test
|
function reverseEntities($string, $replaceEntities = XML_UTIL_ENTITIES_XML,
$encoding = 'ISO-8859-1')
{
switch ($replaceEntities) {
case XML_UTIL_ENTITIES_XML:
return strtr($string, array(
'&' => '&',
'>' => '>',
'<' => '<',
'"' => '"',
''' => '\'' ));
break;
case XML_UTIL_ENTITIES_XML_REQUIRED:
|
php
|
{
"resource": ""
}
|
q266950
|
XML_Util.getXMLDeclaration
|
test
|
function getXMLDeclaration($version = '1.0', $encoding = null,
$standalone = null)
{
$attributes = array(
'version' => $version,
);
// add encoding
if ($encoding !== null) {
|
php
|
{
"resource": ""
}
|
q266951
|
XML_Util.getDocTypeDeclaration
|
test
|
function getDocTypeDeclaration($root, $uri = null, $internalDtd = null)
{
if (is_array($uri)) {
$ref = sprintf(' PUBLIC "%s" "%s"', $uri['id'], $uri['uri']);
} elseif (!empty($uri)) {
$ref = sprintf(' SYSTEM "%s"', $uri);
} else {
$ref = '';
}
if (empty($internalDtd)) {
|
php
|
{
"resource": ""
}
|
q266952
|
XML_Util.attributesToString
|
test
|
function attributesToString($attributes, $sort = true, $multiline = false,
$indent = ' ', $linebreak = "\n", $entities = XML_UTIL_ENTITIES_XML)
{
/*
* second parameter may be an array
*/
if (is_array($sort)) {
if (isset($sort['multiline'])) {
$multiline = $sort['multiline'];
}
if (isset($sort['indent'])) {
$indent = $sort['indent'];
}
if (isset($sort['linebreak'])) {
$multiline = $sort['linebreak'];
}
if (isset($sort['entities'])) {
$entities = $sort['entities'];
}
if (isset($sort['sort'])) {
$sort = $sort['sort'];
} else {
$sort = true;
}
}
$string = '';
if (is_array($attributes) && !empty($attributes)) {
if ($sort) {
ksort($attributes);
}
if ( !$multiline || count($attributes) == 1) {
foreach ($attributes as $key => $value) {
if ($entities != XML_UTIL_ENTITIES_NONE) {
if ($entities === XML_UTIL_CDATA_SECTION) {
$entities = XML_UTIL_ENTITIES_XML;
}
$value = XML_Util::replaceEntities($value, $entities);
}
$string .= ' ' . $key . '="' . $value . '"';
|
php
|
{
"resource": ""
}
|
q266953
|
XML_Util.collapseEmptyTags
|
test
|
function collapseEmptyTags($xml, $mode = XML_UTIL_COLLAPSE_ALL)
{
if ($mode == XML_UTIL_COLLAPSE_XHTML_ONLY) {
return preg_replace(
'/<(area|base(?:font)?|br|col|frame|hr|img|input|isindex|link|meta|'
. 'param)([^>]*)><\/\\1>/s',
'<\\1\\2 />',
|
php
|
{
"resource": ""
}
|
q266954
|
XML_Util.createTag
|
test
|
function createTag($qname, $attributes = array(), $content = null,
$namespaceUri = null, $replaceEntities = XML_UTIL_REPLACE_ENTITIES,
$multiline = false, $indent = '_auto', $linebreak = "\n",
$sortAttributes = true)
{
$tag = array(
'qname' => $qname,
'attributes' => $attributes
);
// add tag content
if ($content !== null) {
$tag['content'] = $content;
|
php
|
{
"resource": ""
}
|
q266955
|
XML_Util.createStartElement
|
test
|
function createStartElement($qname, $attributes = array(), $namespaceUri = null,
$multiline = false, $indent = '_auto', $linebreak = "\n",
$sortAttributes = true)
{
// if no attributes hav been set, use empty attributes
if (!isset($attributes) || !is_array($attributes)) {
$attributes = array();
}
if ($namespaceUri != null) {
$parts = XML_Util::splitQualifiedName($qname);
}
// check for multiline attributes
if ($multiline === true) {
|
php
|
{
"resource": ""
}
|
q266956
|
XML_Util.splitQualifiedName
|
test
|
function splitQualifiedName($qname, $defaultNs = null)
{
if (strstr($qname, ':')) {
$tmp = explode(':', $qname);
return array(
'namespace' => $tmp[0],
|
php
|
{
"resource": ""
}
|
q266957
|
XML_Util.isValidName
|
test
|
function isValidName($string)
{
// check for invalid chars
if (!preg_match('/^[[:alpha:]_]$/', $string{0})) {
return XML_Util::raiseError('XML names may only start with letter '
. 'or underscore', XML_UTIL_ERROR_INVALID_START);
}
// check for invalid chars
if (!preg_match('/^([[:alpha:]_]([[:alnum:]\-\.]*)?:)?[[:alpha:]_]([[:alnum:]\_\-\.]+)?$/',
$string)
|
php
|
{
"resource": ""
}
|
q266958
|
Call.dispatch
|
test
|
public static function dispatch(ICallable $object)
{
$params = $object->getParams();
$call = $object->getCallable();
if (!is_callable($call)) {
throw new CallException("Non callable object found");
}
if ($call instanceof Closure) {
return call_user_func_array($call, $params);
}
$class
|
php
|
{
"resource": ""
}
|
q266959
|
HttpCacheEventSubscriber.onTagResponse
|
test
|
public function onTagResponse(HttpCacheEvent $event)
{
$tags = $event->getData();
if (empty($tags)) {
|
php
|
{
"resource": ""
}
|
q266960
|
HttpCacheEventSubscriber.onInvalidateTag
|
test
|
public function onInvalidateTag(HttpCacheEvent $event)
{
$tags = $event->getData();
if (empty($tags)) {
|
php
|
{
"resource": ""
}
|
q266961
|
ValidationSubscriber.validate
|
test
|
protected function validate(LifecycleEventArgs $args) {
$entity = $args->getEntity();
$metadata = $args->getEntityManager()->getClassMetadata(get_class($entity));
if($this->shouldBeValidated($entity)) {
$rules = $entity->getValidationRules();
$fields = $metadata->getFieldNames();
$data = [];
foreach($fields as $field) {
$data[$field] = $metadata->getFieldValue($entity, $field);
|
php
|
{
"resource": ""
}
|
q266962
|
MessageInterpolationTrait.interpolateMessage
|
test
|
protected function interpolateMessage($message, array $context)//@codingStandardsIgnoreLine Ignore missing type hint
{
$context = array_filter(
$context,
function ($value) {
return (is_scalar($value) || (is_object($value) && method_exists($value, '__toString')));
}
);
|
php
|
{
"resource": ""
}
|
q266963
|
Maths.areSameSpace
|
test
|
public static function areSameSpace(PointInterface $point1, PointInterface $point2)
{
return (bool) (
($point1->is1D() && $point2->is1d()) ||
|
php
|
{
"resource": ""
}
|
q266964
|
Maths.areSamePoint
|
test
|
public static function areSamePoint(PointInterface $point1, PointInterface $point2)
{
if (self::areSameSpace($point1, $point2)) {
if ($point1->is1D()) {
return (bool) ($point1->getAbscissa()==$point2->getAbscissa());
} elseif ($point1->is2D()) {
return (bool) (
($point1->getAbscissa()==$point2->getAbscissa()) &&
($point1->getOrdinate()==$point2->getOrdinate())
);
} elseif ($point1->is3D()) {
return (bool)
|
php
|
{
"resource": ""
}
|
q266965
|
Maths.getLinesIntersection
|
test
|
public static function getLinesIntersection(Line $line1, Line $line2)
{
$div = ($line1->getSlope() - $line2->getSlope());
$x = ($div!=0 ?
(($line2->getYIntercept() - $line1->getYIntercept()) / $div)
|
php
|
{
"resource": ""
}
|
q266966
|
Maths.arePerpendiculars
|
test
|
public function arePerpendiculars(Line $line1, Line $line2)
{
|
php
|
{
"resource": ""
}
|
q266967
|
Maths.areParallels
|
test
|
public static function areParallels(Line $line1, Line $line2)
{
if (
($line1->isHorizontal() && $line2->isHorizontal()) ||
($line1->isVertical() && $line2->isVertical())
) {
return true;
}
$line1->rearrange();
$line2->rearrange();
$abs = array(
$line1->getPointA()->getAbscissa(),
$line1->getPointB()->getAbscissa(),
$line2->getPointA()->getAbscissa(),
$line2->getPointB()->getAbscissa()
);
$ords = array(
$line1->getPointA()->getOrdinate(),
$line1->getPointB()->getOrdinate(),
$line2->getPointA()->getOrdinate(),
$line2->getPointB()->getOrdinate()
);
$e = new Point(
rand(0, 10) + (max($abs) + abs(min($abs))),
rand(0, 10) + (max($ords) + abs(min($ords)))
);
$segAE = new Segment($line1->getPointA(), $e);
$segBE = new Segment($line1->getPointB(), $e);
$intersectCE = self::getLinesIntersection($segAE, $line2);
$segCE = new Segment($intersectCE, $e);
$intersectDE = self::getLinesIntersection($segBE, $line2);
$segDE = new Segment($intersectDE, $e);
/*
echo <<<TYPEOTHER
var demo1 = brd.create('point', [{$line1->getPointA()->x},{$line1->getPointA()->y}], {
name: 'a'
});
var demo2 = brd.create('point', [{$line1->getPointB()->x},{$line1->getPointB()->y}], {
name: 'b'
});
var segment1 = brd.create('line', [demo1,demo2], {straightFirst:false,straightLast:false});
var demo3 = brd.create('point', [{$intersectCE->x},{$intersectCE->y}], {
|
php
|
{
"resource": ""
}
|
q266968
|
Maths.getDirectionByPoints
|
test
|
public static function getDirectionByPoints(PointInterface $point1, PointInterface $point2)
{
if (self::areSameSpace($point1, $point2)) {
$directions = array(
0 => self::getDirectionByCoordinates($point1->getAbscissa(), $point2->getAbscissa())
);
if ($point1->is2D() || $point1->is3D()) {
|
php
|
{
"resource": ""
}
|
q266969
|
Maths.getDirectionByCoordinates
|
test
|
public static function getDirectionByCoordinates($a, $b)
{
if ($a < $b) {
return self::DIRECTION_POSITIVE;
} elseif ($a > $b) {
|
php
|
{
"resource": ""
}
|
q266970
|
ActiveQuery.all
|
test
|
public function all($db = null)
{
if ($this->emulateExecution) {
return resolve([]);
}
return $this->createCommand($db)->thenLazy(
function(CommandInterface $command) {
return $command->queryAll();
|
php
|
{
"resource": ""
}
|
q266971
|
ActiveQuery.prepareAsyncVia
|
test
|
protected function prepareAsyncVia() {
// lazy loading of a relation
$where = $this->where;
$promise = new LazyPromise(function() {
return resolve(true);
});
if ($this->via instanceof self) {
// via junction table
$promise->thenLazy(
function() {
return $this->via->findJunctionRows([$this->primaryModel]);
}
)->thenLazy(
function($viaModels) {
$this->filterByModels($viaModels);
return true;
}
);
} elseif (is_array($this->via)) {
// via relation
/* @var $viaQuery ActiveQuery */
list($viaName, $viaQuery) = $this->via;
$viaModelsPr = $viaQuery->multiple ? $viaQuery->all() : $viaQuery->one();
$viaModelsPr->otherwise(function() use (&$viaQuery) {
return $viaQuery->multiple ? [] : null;
});
$promise->thenLazy(
function() use ($viaModelsPr) {
return $viaModelsPr;
}
)->thenLazy(
|
php
|
{
"resource": ""
}
|
q266972
|
ActiveQuery.removeDuplicatedModels
|
test
|
private function removeDuplicatedModels($models)
{
$hash = [];
/* @var $class ActiveRecordInterface */
$class = $this->modelClass;
$pks = $class::primaryKey();
if (count($pks) > 1) {
// composite primary key
foreach ($models as $i => $model) {
$key = [];
foreach ($pks as $pk) {
if (!isset($model[$pk])) {
// do not continue if the primary key is not part of the result set
break 2;
}
$key[] = $model[$pk];
}
$key = serialize($key);
if (isset($hash[$key])) {
unset($models[$i]);
} else {
$hash[$key] = true;
}
}
} elseif (empty($pks)) {
|
php
|
{
"resource": ""
}
|
q266973
|
ActiveQuery.one
|
test
|
public function one($db = null)
{
if ($this->emulateExecution) {
return reject(false);
}
return $this->createCommand($db)->thenLazy(
function(CommandInterface $command) {
return $command->queryOne();
}
)->thenLazy(
function($row) {
if ($row !== false) {
|
php
|
{
"resource": ""
}
|
q266974
|
HeaderSecurity.isValid
|
test
|
public static function isValid(string $value): bool
{
// Look for:
// \n not preceded by \r, OR
// \r not followed by \n, OR
// \r\n not followed by space or horizontal tab; these are all CRLF attacks
if (preg_match("#(?:(?:(?<!\r)\n)|(?:\r(?!\n))|(?:\r\n(?![ \t])))#", $value)) {
return false;
}
// Non-visible, non-whitespace characters
// 9 === horizontal tab
// 10 === line feed
|
php
|
{
"resource": ""
}
|
q266975
|
HeaderSecurity.assertValid
|
test
|
public static function assertValid(string $value): void
{
if (! self::isValid($value)) {
throw new InvalidArgumentException(
sprintf(
|
php
|
{
"resource": ""
}
|
q266976
|
Tunes.request
|
test
|
public function request()
{
if ('' !== $this->defaultOptions['callback']) {
$msg = 'Cannot run query when callback is set. Get query using getRawRequestUrl().';
throw new \BadMethodCallException($msg);
}
$this->buildSpecificRequestUri();
try {
if (null === $content = $this->getHttpClient()->getContent($this->getRawRequestUrl())) {
throw new \RuntimeException('The request was not successful.');
}
} catch (\RuntimeException $e) {
throw new \RuntimeException('The request was not successful.');
}
if (self::RESULT_ARRAY === $this->resultFormat) {
|
php
|
{
"resource": ""
}
|
q266977
|
Tunes.buildRequestUri
|
test
|
protected function buildRequestUri()
{
$requestParameters = array();
// add entity
if (!empty($this->defaultOptions['entity'])) {
$tmp = array_keys($this->defaultOptions['entity']);
$key = array_pop($tmp);
$requestParameters[] = 'entity=' . $this->defaultOptions['entity'][$key];
}
// add media type
if (!empty($this->defaultOptions['mediaType'])) {
$requestParameters[] = 'media=' . $this->defaultOptions['mediaType'];
}
// add attribute
if (!empty($this->defaultOptions['attribute'])) {
$requestParameters[] = 'attribute=' . $this->defaultOptions['attribute'];
}
// add language
if (!empty($this->defaultOptions['language'])) {
$requestParameters[] = 'lang=' . $this->defaultOptions['language'];
}
// add limit
if ($this->defaultOptions['limit'] <> 100) {
$requestParameters[] = 'limit=' . $this->defaultOptions['limit'];
}
// add country
if ($this->defaultOptions['country'] != 'us') {
$requestParameters[] = 'country=' . $this->defaultOptions['country'];
}
|
php
|
{
"resource": ""
}
|
q266978
|
Tunes.setLanguage
|
test
|
public function setLanguage($language = 'en_us')
{
if (in_array($language, $this->languageList)) {
|
php
|
{
"resource": ""
}
|
q266979
|
Tunes.setMediaType
|
test
|
public function setMediaType($mediatype = self::MEDIATYPE_ALL)
{
if (in_array($mediatype, $this->mediaTypes)) {
|
php
|
{
"resource": ""
}
|
q266980
|
Tunes.setResultFormat
|
test
|
public function setResultFormat($format = self::RESULT_ARRAY)
{
if (in_array($format, $this->resultFormats)) {
|
php
|
{
"resource": ""
}
|
q266981
|
Tunes.setLimit
|
test
|
public function setLimit($limit = 100)
{
// the limit must be within the boundaries of the service
if ($limit <= 0 || $limit > 200) {
throw
|
php
|
{
"resource": ""
}
|
q266982
|
Tunes.setEntity
|
test
|
public function setEntity($entity = array())
{
// check if only one entry is given
if (count($entity) <> 1) {
throw new \InvalidArgumentException('Must be set with one key/value-pair!');
}
// fetch key from parameter
|
php
|
{
"resource": ""
}
|
q266983
|
Tunes.setAttribute
|
test
|
public function setAttribute($attribute = '')
{
if ('' === $this->defaultOptions['mediaType']) {
throw new \InvalidArgumentException('Attribute relates to media type but no media type is set.');
}
// check if the attribute is in the set of attributes for media type
if (in_array($attribute, $this->attributesTypes[$this->defaultOptions['mediaType']])) {
|
php
|
{
"resource": ""
}
|
q266984
|
Tunes.setCallback
|
test
|
public function setCallback($callback = '')
{
if (self::RESULT_JSON !== $this->getResultFormat()) {
throw new \BadMethodCallException('Callback can only be
|
php
|
{
"resource": ""
}
|
q266985
|
Tunes.setExplicit
|
test
|
public function setExplicit($setting = 'yes')
{
if (in_array($setting, $this->explicitTypes)) {
|
php
|
{
"resource": ""
}
|
q266986
|
ApiPhoto.getPhotos
|
test
|
protected function getPhotos($galleryId)
{
if (! is_null($ids =
|
php
|
{
"resource": ""
}
|
q266987
|
PEAR_Common.log
|
test
|
function log($level, $msg, $append_crlf = true)
{
if ($this->debug >= $level) {
if (!class_exists('PEAR_Frontend')) {
require_once 'PEAR/Frontend.php';
}
$ui = &PEAR_Frontend::singleton();
|
php
|
{
"resource": ""
}
|
q266988
|
PEAR_Common.mkTempDir
|
test
|
function mkTempDir($tmpdir = '')
{
$topt = $tmpdir ? array('-t', $tmpdir) : array();
$topt = array_merge($topt, array('-d', 'pear'));
if (!class_exists('System')) {
require_once 'System.php';
}
|
php
|
{
"resource": ""
}
|
q266989
|
PEAR_Common.infoFromTgzFile
|
test
|
function infoFromTgzFile($file)
{
$packagefile = &new PEAR_PackageFile($this->config);
$pf
|
php
|
{
"resource": ""
}
|
q266990
|
PEAR_Common.infoFromDescriptionFile
|
test
|
function infoFromDescriptionFile($descfile)
{
$packagefile = &new PEAR_PackageFile($this->config);
$pf
|
php
|
{
"resource": ""
}
|
q266991
|
PEAR_Common.infoFromString
|
test
|
function infoFromString($data)
{
$packagefile = &new PEAR_PackageFile($this->config);
$pf
|
php
|
{
"resource": ""
}
|
q266992
|
PEAR_Common.infoFromAny
|
test
|
function infoFromAny($info)
{
if (is_string($info) && file_exists($info)) {
$packagefile = &new PEAR_PackageFile($this->config);
$pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($pf)) {
$errs = $pf->getUserinfo();
if (is_array($errs)) {
foreach ($errs as $error) {
|
php
|
{
"resource": ""
}
|
q266993
|
Articles.getWithOffers
|
test
|
public function getWithOffers()
{
if ((int) $this->id <= 0) {
throw new NullPointerException("Id is not set.");
}
// build url
$url = $this->base_url . str_replace("{id}", $this->id, $this->_url_offers);
// get data from server
|
php
|
{
"resource": ""
}
|
q266994
|
Articles.getAllWithOffers
|
test
|
public function getAllWithOffers()
{
// build url
$url = $this->base_url . $this->_url_all_offers;
// get data from server
$data = $this->getDataFromUrl($url);
|
php
|
{
"resource": ""
}
|
q266995
|
Articles.search
|
test
|
public function search()
{
if (strlen($this->ean) <= 0) {
throw new NullPointerException("EAN is not set.");
}
$params = array(
"ean" => $this->ean
);
$url = $this->base_url . self::URL_SEARCH . "?" . http_build_query($params);
|
php
|
{
"resource": ""
}
|
q266996
|
Logger.setFileHandler
|
test
|
protected function setFileHandler(string $logFile, int $logLevel = null)
{
$this->logFile = $logFile;
|
php
|
{
"resource": ""
}
|
q266997
|
Logger.setMailHandler
|
test
|
protected function setMailHandler(string $emailTo, string $emailSubject, string $emailFrom, int $logLevel)
|
php
|
{
"resource": ""
}
|
q266998
|
Logger.getLogs
|
test
|
public function getLogs(int $limit = 0)
{
if (!file_exists($this->logFile)) {
return [];
}
$lineCount = 0;
$fileAsc = file($this->logFile);
$file = array_reverse($fileAsc);
$arrOutput = [];
foreach ($file as $row) {
$currentRow = $this->makeLogRow($row);
if (!$currentRow) {
continue;
|
php
|
{
"resource": ""
}
|
q266999
|
Logger.makeLogRow
|
test
|
protected function makeLogRow(string $row)
{
//[2017-07-22 23:06:48]
$date = substr($row, 1, 19);
if (!Validator::validateDate($date)) {
return false;
}
$fullMsg = substr($row, 22);
$arrMsg = explode(":", $fullMsg);
$logLevel = $arrMsg[0];
|
php
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.