_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q248700
Font.color
validation
private function color(string $color): Font { $this->color = $color; if ($this->background) { $this->turnToBackground(); } return $this; }
php
{ "resource": "" }
q248701
PasswordHelper.lookup
validation
public function lookup($hash, $className = 'Orkestra\Bundle\ApplicationBundle\Entity\User') { try { return $this->hashedEntityHelper->lookup($hash, $className); } catch (\RuntimeException $e) { return null; } }
php
{ "resource": "" }
q248702
PasswordHelper.sendPasswordResetEmail
validation
public function sendPasswordResetEmail(UserInterface $user, $subject = 'Password reset request') { $hashedEntity = $this->createHash($user); $this->emailHelper->createAndSendMessageFromTemplate( 'OrkestraApplicationBundle:Email:setPassword.html.twig', array( 'user' => $user, 'hash' => $hashedEntity->getHash() ), $subject, $user->getEmail() ); return $hashedEntity; }
php
{ "resource": "" }
q248703
Native.getContent
validation
public function getContent(string $name, array $data = []): string { $cacheName = $name; if ('' == $name) { $this->isRouteView = true; $stack = debug_backtrace(); foreach ($stack as $item) { if (false !== stripos($item['file'], DIRECTORY_SEPARATOR . 'Route' . DIRECTORY_SEPARATOR)) { $cacheName = pathinfo($item['file'], PATHINFO_DIRNAME) . '/' . $name; $cacheName = explode('Route' . DIRECTORY_SEPARATOR, $cacheName)[1]; $cacheName = 'route_' . str_replace(['/', '\\'], '_', $cacheName); break; } } } $cacheName .= '_' . $this->language . '.html.php'; $path = $this->packageRoot . '/view/_cache/' . str_replace('/', '_', $cacheName); $exist = file_exists($path); if (!$this->cache || !$exist) { $code = $this->compile($name . '/view.html.php', true, true, true); $code = preg_replace(['/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s'], ['>', '<', '\\1'], $code); if ($exist) { $fh = fopen($path, 'r+b'); } else { $fh = fopen($path, 'wb'); } if (flock($fh, LOCK_EX)) { ftruncate($fh, 0); fwrite($fh, $code); flock($fh, LOCK_UN); } fclose($fh); } $fh = fopen($path, 'rb'); if (flock($fh, LOCK_SH)) { $html = self::renderTemplate($path, $data); flock($fh, LOCK_UN); fclose($fh); return $html; } throw new \RuntimeException('Can\'t render template'); }
php
{ "resource": "" }
q248704
Native.renderTemplate
validation
private static function renderTemplate(string $__file__, array $data): string { ob_start(); extract($data); include $__file__; return ob_get_clean(); }
php
{ "resource": "" }
q248705
PasswordSetController.newAction
validation
public function newAction(Request $request, $hash) { $passwordHelper = $this->get('orkestra.application.helper.password'); $hashedEntityHelper = $this->get('orkestra.application.helper.hashed_entity'); $hashedEntity = $passwordHelper->lookup($hash); if (!$hashedEntity) { throw new EntityNotFoundException(); } $user = $hashedEntity->getReferencedObject(); $hashedEntityHelper->invalidate($hashedEntity); $em = $this->getDoctrine()->getManager(); $em->persist($hashedEntity); $em->flush(); if ($user) { $request->getSession()->set(PasswordSetController::CURRENT_USER_ID_KEY, $user->getId()); $form = $this->getSetPasswordForm(); return array( 'form' => $form->createView() ); } else { throw $this->createNotFoundException('No user was found.'); } }
php
{ "resource": "" }
q248706
File.createFromUploadedFile
validation
public static function createFromUploadedFile(UploadedFile $upload, $uploadPath, $filename = null) { if (!$upload->isValid()) { throw new UploadException(sprintf('An error occurred during file upload. Error code: %s', $upload->getError())); } elseif (($uploadPath = realpath($uploadPath . '/')) === false) { throw new UploadException('An error occurred during file upload. The specified upload path is invalid.'); } if (!$filename) { $fullPath = sprintf( '%s%s%s.%s', rtrim($uploadPath, DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, uniqid(), ($upload->getExtension() ?: ($upload->guessExtension() ?: 'file')) ); } else { $fullPath = rtrim($uploadPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $filename; } $file = new self($fullPath, $upload->getClientOriginalName(), $upload->getMimeType(), $upload->getClientSize(), md5_file($upload->getRealPath())); $file->_uploadedFile = $upload; return $file; }
php
{ "resource": "" }
q248707
File.moveUploadedFile
validation
public function moveUploadedFile() { $this->dateCreated = new DateTime(); if (null === $this->_uploadedFile) { return; } $this->_uploadedFile->move(dirname($this->path), basename($this->path)); $this->_uploadedFile = null; }
php
{ "resource": "" }
q248708
ConsoleColor.addColor
validation
public function addColor($color, $code = null) { $newColors = $this->parseColor($color, $code); $this->colors = array_merge($this->colors, $newColors); return $this; }
php
{ "resource": "" }
q248709
ConsoleColor.colorize
validation
protected function colorize($str, $attrs) { $start = $this->start($attrs); return $start.$str.$this->end(); }
php
{ "resource": "" }
q248710
ConsoleColor.parseColor
validation
protected function parseColor($color, $code = null) { $colors = is_array($color) ? $color : [$color => $code]; $return = []; array_walk($colors, function ($code, $color) use (&$return) { $color = $this->snakeCase($color); $return[$color] = $code; }); return $return; }
php
{ "resource": "" }
q248711
UserController.newAction
validation
public function newAction() { $user = new User(); $form = $this->createForm(UserType::class, $user); return array( 'user' => $user, 'form' => $form->createView() ); }
php
{ "resource": "" }
q248712
UserController.createAction
validation
public function createAction(Request $request) { $user = new User(); $form = $this->createForm(UserType::class, $user); $form->bind($request); if ($form->isValid()) { $factory = $this->get('security.encoder_factory'); $encoder = $factory->getEncoder($user); $user->setPassword($encoder->encodePassword($user->getPassword(), $user->getSalt())); $em = $this->getDoctrine()->getManager(); $em->persist($user); $em->flush(); $this->get('session')->getFlashBag()->set('success', 'The user has been created.'); return $this->redirect($this->generateUrl('orkestra_user_show', array('id' => $user->getId()))); } return array( 'user' => $user, 'form' => $form->createView() ); }
php
{ "resource": "" }
q248713
UserController.resetPasswordAction
validation
public function resetPasswordAction(Request $request, $id) { $em = $this->getDoctrine()->getManager(); $user = $em->getRepository('Orkestra\Bundle\ApplicationBundle\Entity\User')->find($id); if (!$user) { throw $this->createNotFoundException('Unable to locate User'); } $form = $this->createForm(ChangePasswordType::class, null, array('require_current' => false)); if ($request->isMethod('POST')) { $form->bind($request); if ($form->isValid()) { $data = $form->getData(); $factory = $this->get('security.encoder_factory'); $encoder = $factory->getEncoder($user); $user->setPassword($encoder->encodePassword($data['password'], $user->getSalt())); $em->persist($user); $em->flush(); $this->get('session')->getFlashBag()->set('success', 'The password has been changed.'); return $this->redirect($this->generateUrl('orkestra_user_show', array('id' => $id))); } } return array( 'user' => $user, 'form' => $form->createView(), ); }
php
{ "resource": "" }
q248714
UserController.editAction
validation
public function editAction($id) { $em = $this->getDoctrine()->getManager(); $user = $em->getRepository('Orkestra\Bundle\ApplicationBundle\Entity\User')->find($id); if (!$user) { throw $this->createNotFoundException('Unable to locate User'); } $form = $this->createForm(UserType::class, $user, array('include_password' => false)); return array( 'user' => $user, 'form' => $form->createView(), ); }
php
{ "resource": "" }
q248715
UserController.updateAction
validation
public function updateAction(Request $request, $id) { $em = $this->getDoctrine()->getManager(); $user = $em->getRepository('Orkestra\Bundle\ApplicationBundle\Entity\User')->find($id); if (!$user) { throw $this->createNotFoundException('Unable to locate User'); } $form = $this->createForm(UserType::class, $user, array('include_password' => false)); $form->bind($request); if ($form->isValid()) { $em->persist($user); $em->flush(); $this->get('session')->getFlashBag()->set('success', 'Your changes have been saved.'); return $this->redirect($this->generateUrl('orkestra_user_show', array('id' => $id))); } return array( 'user' => $user, 'form' => $form->createView(), ); }
php
{ "resource": "" }
q248716
ModifyServiceDefinitionsPass.configureEmailHelper
validation
private function configureEmailHelper(ContainerBuilder $container) { if (!class_exists('Swift_Mailer')) { $definition = $container->getDefinition('orkestra.application.helper.email'); $definition->setClass('Orkestra\Bundle\ApplicationBundle\Helper\EmailHelper\MisconfiguredEmailHelper'); $definition->setArguments(array()); } }
php
{ "resource": "" }
q248717
ArbitrarySetLoader.getEntitiesByIds
validation
public function getEntitiesByIds($identifier, array $values) { $accessor = PropertyAccess::createPropertyAccessor(); return array_filter(is_array($this->entities) ? $this->entities : $this->entities->toArray(), function ($entity) use ($identifier, $values, $accessor) { return in_array($accessor->getValue($entity, $identifier), $values); }); }
php
{ "resource": "" }
q248718
FileController.downloadAction
validation
public function downloadAction($id) { $em = $this->getDoctrine()->getManager(); /** @var $file \Orkestra\Bundle\ApplicationBundle\Entity\File */ $file = $em->find('Orkestra\Bundle\ApplicationBundle\Entity\File', $id); if (!$file) { throw $this->createNotFoundException('Unable to locate File'); } $securityContext = $this->get('security.authorization_checker'); foreach ($file->getGroups() as $group) { if (!$securityContext->isGranted($group->getRole())) { throw $this->createNotFoundException('Unable to locate File'); } } return new Response($file->getContent(), 200, array( 'Content-Type' => $file->getMimeType(), 'Content-Disposition' => sprintf('attachment; filename="%s"', $file->getFilename()) )); }
php
{ "resource": "" }
q248719
Controller.getFormFor
validation
public function getFormFor($entity, $className = null, array $options = array()) { if (empty($this->_formHelper) && ($this->_formHelper = $this->get('orkestra.application.helper.form')) == null) { throw new \RuntimeException('Orkestra FormHelper is not registered as a service'); } $type = $this->container->get('orkestra.application.helper.form')->getType($entity, $className); return $this->createForm($type, $entity, $options); }
php
{ "resource": "" }
q248720
Index.getContent
validation
public function getContent() { $this->absolute(); //if the pat is not a real file if (!is_file($this->data)) { //throw an exception Exception::i() ->setMessage(self::ERROR_PATH_IS_NOT_FILE) ->addVariable($this->data) ->trigger(); } return file_get_contents($this->data); }
php
{ "resource": "" }
q248721
Index.getMime
validation
public function getMime() { $this->absolute(); //mime_content_type seems to be deprecated in some versions of PHP //if it does exist then lets use it if (function_exists('mime_content_type')) { return mime_content_type($this->data); } //if not then use the replacement funciton fileinfo //see: http://www.php.net/manual/en/function.finfo-file.php if (function_exists('finfo_open')) { $resource = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($resource, $this->data); finfo_close($finfo); return $mime; } //ok we have to do this manually //get this file extension $extension = strtolower($this->getExtension()); //get the list of mimetypes stored locally $types = self::$mimeTypes; //if this extension exissts in the types if (isset($types[$extension])) { //return the mimetype return $types[$extension]; } //return text/plain by default return $types['class']; }
php
{ "resource": "" }
q248722
Index.setContent
validation
public function setContent($content) { //argument 1 must be string Argument::i()->test(1, 'string'); try { $this->absolute(); } catch (\Eden\Path\Exception $e) { $this->touch(); } file_put_contents($this->data, $content); return $this; }
php
{ "resource": "" }
q248723
StringBuilder.changeEncoding
validation
public function changeEncoding($encoding) { $encoding = (string) $encoding; $this->string = iconv($this->encoding, $encoding, $this->string); $this->encoding = $encoding; return $this; }
php
{ "resource": "" }
q248724
StringBuilder.startsWith
validation
public function startsWith($string) { $string = static::convertString($string, $this->encoding); return $string === $this->substring(0, (mb_strlen($string, $this->encoding) - 1))->__toString(); }
php
{ "resource": "" }
q248725
StringBuilder.endsWith
validation
public function endsWith($string) { $string = static::convertString($string, $this->encoding); return $string === $this->substring($this->length() - mb_strlen($string, $this->encoding))->__toString(); }
php
{ "resource": "" }
q248726
StringBuilder.charAt
validation
public function charAt($index) { $index = (int) $index; if ($index < 0 || $index >= $this->length()) { throw new \OutOfBoundsException(); } return mb_substr($this->string, $index, 1, $this->encoding); }
php
{ "resource": "" }
q248727
StringBuilder.indexOf
validation
public function indexOf($string, $offset = null) { $string = static::convertString($string, $this->encoding); $offset = $offset !== null ? (int) $offset : null; if ($offset !== null && ($offset < 0 || $offset >= $this->length())) { throw new \OutOfBoundsException(); } return mb_strpos($this->string, $string, $offset, $this->encoding); }
php
{ "resource": "" }
q248728
StringBuilder.lastIndexOf
validation
public function lastIndexOf($string, $offset = null) { $string = static::convertString($string, $this->encoding); $offset = $offset !== null ? (int) $offset : null; if ($offset !== null && ($offset < 0 || $offset >= $this->length())) { throw new \OutOfBoundsException(); } return mb_strrpos($this->string, $string, $offset, $this->encoding); }
php
{ "resource": "" }
q248729
StringBuilder.append
validation
public function append($string) { $string = static::convertString($string, $this->encoding); $this->string .= $string; return $this; }
php
{ "resource": "" }
q248730
StringBuilder.insert
validation
public function insert($offset, $string) { $offset = (int) $offset; $string = static::convertString($string, $this->encoding); if ($offset < 0 || $offset >= $this->length()) { throw new \OutOfBoundsException(); } $this->string = mb_substr($this->string, 0, $offset, $this->encoding) . $string . mb_substr($this->string, $offset, $this->length(), $this->encoding); return $this; }
php
{ "resource": "" }
q248731
StringBuilder.reverse
validation
public function reverse() { $length = $this->length(); $reversed = ''; while ($length-- > 0) { $reversed .= mb_substr($this->string, $length, 1, $this->encoding); } $this->string = $reversed; return $this; }
php
{ "resource": "" }
q248732
StringBuilder.setLength
validation
public function setLength($newLength, $padding = ' ') { $newLength = (int) $newLength; $currentLength = $this->length(); if ($newLength != $currentLength) { while ($newLength > $this->length()) { $this->string .= $padding; } if ($newLength < $this->length()) { $this->string = mb_substr($this->string, 0, $newLength, $this->encoding); } } return $this; }
php
{ "resource": "" }
q248733
StringBuilder.trim
validation
public function trim($characters = null) { $this->string = trim($this->string, $characters); return $this; }
php
{ "resource": "" }
q248734
StringBuilder.trimLeft
validation
public function trimLeft($characters = null) { $this->string = ltrim($this->string, $characters); return $this; }
php
{ "resource": "" }
q248735
StringBuilder.trimRight
validation
public function trimRight($characters = null) { $this->string = rtrim($this->string, $characters); return $this; }
php
{ "resource": "" }
q248736
StringBuilder.convertString
validation
private static function convertString($string, $outputEncoding) { if ($string instanceof StringBuilder) { $inputEncoding = $string->getEncoding(); } else { $inputEncoding = mb_detect_encoding((string) $string); } $string = (string) $string; if ($inputEncoding != $outputEncoding) { $string = iconv($inputEncoding, $outputEncoding, $string); } return $string; }
php
{ "resource": "" }
q248737
EmailHelper.createMessageFromTemplateEntity
validation
public function createMessageFromTemplateEntity(EmailTemplate $template, array $parameters = array()) { $subject = $this->renderStringTemplate($template->getSubject(), $parameters); $recipient = $this->renderStringTemplate($template->getRecipient(), $parameters); $body = $this->renderStringTemplate($template->getBody(), $parameters); $sender = $template->getSender() ?: $this->defaultSender; $message = new \Swift_Message($subject, $body, $template->getMimeType()); $message->setFrom($sender) ->setSender($sender) ->setTo($recipient); if ($template->hasCc()) { $message->setCc($template->getCc()); } if ($template->hasAltBody()) { $altBody = $this->renderStringTemplate($template->getAltBody(), $parameters); $message->addPart($altBody, $template->getAltMimeType()); } return $message; }
php
{ "resource": "" }
q248738
EmailHelper.createMessageFromTemplateFile
validation
public function createMessageFromTemplateFile($template, $params, $subject, $recipient, $sender = null) { $body = $this->templating->render($template, $params); if (!$sender) { $sender = $this->defaultSender; } $message = new \Swift_Message(); $message->setFrom($sender) ->setReplyTo($sender) ->setTo($recipient) ->setSubject($subject) ->setBody($body, 'text/html'); return $message; }
php
{ "resource": "" }
q248739
EmailHelper.createAndSendMessageFromTemplate
validation
public function createAndSendMessageFromTemplate() { $args = func_get_args(); if (empty($args[0])) { throw new \RuntimeException('First parameter must be a template filename or EmailTemplate entity'); } elseif ($args[0] instanceof EmailTemplate) { $method = 'createMessageFromTemplateEntity'; } else { $method = 'createMessageFromTemplateFile'; } $message = call_user_func_array(array($this, $method), $args); $this->mailer->send($message); return true; }
php
{ "resource": "" }
q248740
EmailHelper.renderStringTemplate
validation
protected function renderStringTemplate($template, $parameters = array()) { $template = $this->environment->createTemplate($template); return $template->render($parameters); }
php
{ "resource": "" }
q248741
CurlService.requestJson
validation
public function requestJson($method, $url, $options=array()){ $options['headers'][] = 'Content-Type: application/json'; $options['headers'][] = 'Content-Length: ' . strlen($options['body']); $this->request($method, $url, $options); }
php
{ "resource": "" }
q248742
DbtextCollectionManager.clearCache
validation
public function clearCache(string $namespace = null) { if (null !== $namespace) { $this->cacheStore->remove(self::APP_CACHE_PREFIX . $namespace, array()); return; } $this->cacheStore->clear(); }
php
{ "resource": "" }
q248743
DbtextDao.getOrCreateGroup
validation
private function getOrCreateGroup(string $namespace): Group { $group = $this->em->find(Group::getClass(), $namespace); if (null !== $group) { return $group; } $group = new Group($namespace); $t = $this->tm->createTransaction(); $this->em->persist($group); $t->commit(); return $group; }
php
{ "resource": "" }
q248744
DbtextHtmlBuilder.tf
validation
public function tf(string $key, array $args = null, array $replacements = null, string ...$namespaces) { $this->view->out($this->getTf($key, $args, $replacements, ...$namespaces)); }
php
{ "resource": "" }
q248745
DbtextHtmlBuilder.getTf
validation
public function getTf(string $key, array $args = null, array $replacements = null, string ...$namespaces) { if (empty($namespaces)) { $namespaces = $this->meta->getNamespaces(); } $translatedText = $this->textService->tf($namespaces, $key, $args, ...$this->meta->getN2nLocales()); $replacedText = HtmlBuilderMeta::replace($translatedText, $replacements, $this->view); return new Raw($replacedText); }
php
{ "resource": "" }
q248746
DbtextHtmlBuilderMeta.assignNamespace
validation
public function assignNamespace(string $namespace, $prepend = false) { if ($prepend) { array_unshift($this->namespaces, $namespace); return; } array_push($this->namespaces, $namespace); }
php
{ "resource": "" }
q248747
TokenizerBase.setDoc
validation
function setDoc($doc, $pos = 0) { $this->doc = $doc; $this->size = strlen($doc); $this->setPos($pos); }
php
{ "resource": "" }
q248748
TokenizerBase.getTokenString
validation
function getTokenString($start_offset = 0, $end_offset = 0) { $token_start = ((is_int($this->token_start)) ? $this->token_start : $this->pos) + $start_offset; $len = $this->pos - $token_start + 1 + $end_offset; return (($len > 0) ? substr($this->doc, $token_start, $len) : ''); }
php
{ "resource": "" }
q248749
TokenizerBase.setWhitespace
validation
function setWhitespace($ws) { if (is_array($ws)) { $this->whitespace = array_fill_keys(array_values($ws), true); $this->buildCharMap(); } else { $this->setWhiteSpace(str_split($ws)); } }
php
{ "resource": "" }
q248750
TokenizerBase.setIdentifiers
validation
function setIdentifiers($ident) { if (is_array($ident)) { $this->identifiers = array_fill_keys(array_values($ident), true); $this->buildCharMap(); } else { $this->setIdentifiers(str_split($ident)); } }
php
{ "resource": "" }
q248751
TokenizerBase.addError
validation
function addError($error) { $this->errors[] = htmlentities($error.' at '.($this->line_pos[0] + 1).', '.($this->pos - $this->line_pos[1] + 1).'!'); }
php
{ "resource": "" }
q248752
TokenizerBase.parse_linebreak
validation
protected function parse_linebreak() { if($this->doc[$this->pos] === "\r") { ++$this->line_pos[0]; if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === "\n")) { ++$this->pos; } $this->line_pos[1] = $this->pos; } elseif($this->doc[$this->pos] === "\n") { ++$this->line_pos[0]; $this->line_pos[1] = $this->pos; } }
php
{ "resource": "" }
q248753
TokenizerBase.next
validation
function next() { $this->token_start = null; if (++$this->pos < $this->size) { if (isset($this->char_map[$this->doc[$this->pos]])) { if (is_string($this->char_map[$this->doc[$this->pos]])) { return ($this->token = $this->{$this->char_map[$this->doc[$this->pos]]}()); } else { return ($this->token = $this->char_map[$this->doc[$this->pos]]); } } else { return ($this->token = self::TOK_UNKNOWN); } } else { return ($this->token = self::TOK_NULL); } }
php
{ "resource": "" }
q248754
TokenizerBase.next_no_whitespace
validation
function next_no_whitespace() { $this->token_start = null; while (++$this->pos < $this->size) { if (!isset($this->whitespace[$this->doc[$this->pos]])) { if (isset($this->char_map[$this->doc[$this->pos]])) { if (is_string($this->char_map[$this->doc[$this->pos]])) { return ($this->token = $this->{$this->char_map[$this->doc[$this->pos]]}()); } else { return ($this->token = $this->char_map[$this->doc[$this->pos]]); } } else { return ($this->token = self::TOK_UNKNOWN); } } else { $this->parse_linebreak(); } } return ($this->token = self::TOK_NULL); }
php
{ "resource": "" }
q248755
TokenizerBase.next_search
validation
function next_search($characters, $callback = true) { $this->token_start = $this->pos; if (!is_array($characters)) { $characters = array_fill_keys(str_split($characters), true); } while(++$this->pos < $this->size) { if (isset($characters[$this->doc[$this->pos]])) { if ($callback && isset($this->char_map[$this->doc[$this->pos]])) { if (is_string($this->char_map[$this->doc[$this->pos]])) { return ($this->token = $this->{$this->char_map[$this->doc[$this->pos]]}()); } else { return ($this->token = $this->char_map[$this->doc[$this->pos]]); } } else { return ($this->token = self::TOK_UNKNOWN); } } else { $this->parse_linebreak(); } } return ($this->token = self::TOK_NULL); }
php
{ "resource": "" }
q248756
TokenizerBase.next_pos
validation
function next_pos($needle, $callback = true) { $this->token_start = $this->pos; if (($this->pos < $this->size) && (($p = stripos($this->doc, $needle, $this->pos + 1)) !== false)) { $len = $p - $this->pos - 1; if ($len > 0) { $str = substr($this->doc, $this->pos + 1, $len); if (($l = strrpos($str, "\n")) !== false) { ++$this->line_pos[0]; $this->line_pos[1] = $l + $this->pos + 1; $len -= $l; if ($len > 0) { $str = substr($str, 0, -$len); $this->line_pos[0] += substr_count($str, "\n"); } } } $this->pos = $p; if ($callback && isset($this->char_map[$this->doc[$this->pos]])) { if (is_string($this->char_map[$this->doc[$this->pos]])) { return ($this->token = $this->{$this->char_map[$this->doc[$this->pos]]}()); } else { return ($this->token = $this->char_map[$this->doc[$this->pos]]); } } else { return ($this->token = self::TOK_UNKNOWN); } } else { $this->pos = $this->size; return ($this->token = self::TOK_NULL); } }
php
{ "resource": "" }
q248757
TokenizerBase.expect
validation
protected function expect($token, $do_next = true, $try_next = false, $next_on_match = 1) { if ($do_next) { if ($do_next === 1) { $this->next(); } else { $this->next_no_whitespace(); } } if (is_int($token)) { if (($this->token !== $token) && ((!$try_next) || ((($try_next === 1) && ($this->next() !== $token)) || (($try_next === true) && ($this->next_no_whitespace() !== $token))))) { $this->addError('Unexpected "'.$this->getTokenString().'"'); return false; } } else { if (($this->doc[$this->pos] !== $token) && ((!$try_next) || (((($try_next === 1) && ($this->next() !== self::TOK_NULL)) || (($try_next === true) && ($this->next_no_whitespace() !== self::TOK_NULL))) && ($this->doc[$this->pos] !== $token)))) { $this->addError('Expected "'.$token.'", but found "'.$this->getTokenString().'"'); return false; } } if ($next_on_match) { if ($next_on_match === 1) { $this->next(); } else { $this->next_no_whitespace(); } } return true; }
php
{ "resource": "" }
q248758
HtmlParserBase.parse_text
validation
function parse_text() { $len = $this->pos - 1 - $this->status['last_pos']; $this->status['text'] = (($len > 0) ? substr($this->doc, $this->status['last_pos'] + 1, $len) : ''); }
php
{ "resource": "" }
q248759
HtmlParserBase.parse_comment
validation
function parse_comment() { $this->pos += 3; if ($this->next_pos('-->', false) !== self::TOK_UNKNOWN) { $this->status['comment'] = $this->getTokenString(1, -1); --$this->pos; } else { $this->status['comment'] = $this->getTokenString(1, -1); $this->pos += 2; } $this->status['last_pos'] = $this->pos; return true; }
php
{ "resource": "" }
q248760
HtmlParserBase.parse_doctype
validation
function parse_doctype() { $start = $this->pos; if ($this->next_search('[>', false) === self::TOK_UNKNOWN) { if ($this->doc[$this->pos] === '[') { if (($this->next_pos(']', false) !== self::TOK_UNKNOWN) || ($this->next_pos('>', false) !== self::TOK_UNKNOWN)) { $this->addError('Invalid doctype'); return false; } } $this->token_start = $start; $this->status['dtd'] = $this->getTokenString(2, -1); $this->status['last_pos'] = $this->pos; return true; } else { $this->addError('Invalid doctype'); return false; } }
php
{ "resource": "" }
q248761
HtmlParserBase.parse_cdata
validation
function parse_cdata() { if ($this->next_pos(']]>', false) === self::TOK_UNKNOWN) { $this->status['cdata'] = $this->getTokenString(9, -1); $this->status['last_pos'] = $this->pos + 2; return true; } else { $this->addError('Invalid cdata tag'); return false; } }
php
{ "resource": "" }
q248762
HtmlParserBase.parse_asp
validation
function parse_asp() { $start = $this->pos; if ($this->next_pos('%>', false) !== self::TOK_UNKNOWN) { $this->pos -= 2; //End of file } $len = $this->pos - 1 - $start; $this->status['text'] = (($len > 0) ? substr($this->doc, $start + 1, $len) : ''); $this->status['last_pos'] = ++$this->pos; return true; }
php
{ "resource": "" }
q248763
HtmlParserBase.parse_style
validation
function parse_style() { if ($this->parse_attributes() && ($this->token === self::TOK_TAG_CLOSE) && ($start = $this->pos) && ($this->next_pos('</style>', false) === self::TOK_UNKNOWN)) { $len = $this->pos - 1 - $start; $this->status['text'] = (($len > 0) ? substr($this->doc, $start + 1, $len) : ''); $this->pos += 7; $this->status['last_pos'] = $this->pos; return true; } else { $this->addError('No end for style tag found'); return false; } }
php
{ "resource": "" }
q248764
HtmlParserBase.parse_tag_default
validation
function parse_tag_default() { if ($this->status['closing_tag']) { $this->status['attributes'] = array(); $this->next_no_whitespace(); } else { if (!$this->parse_attributes()) { return false; } } if ($this->token !== self::TOK_TAG_CLOSE) { if ($this->token === self::TOK_SLASH_FORWARD) { $this->status['self_close'] = true; $this->next(); } elseif ((($this->status['tag_name'][0] === '?') && ($this->doc[$this->pos] === '?')) || (($this->status['tag_name'][0] === '%') && ($this->doc[$this->pos] === '%'))) { $this->status['self_close'] = true; $this->pos++; if (isset($this->char_map[$this->doc[$this->pos]]) && (!is_string($this->char_map[$this->doc[$this->pos]]))) { $this->token = $this->char_map[$this->doc[$this->pos]]; } else { $this->token = self::TOK_UNKNOWN; } }/* else { $this->status['self_close'] = false; }*/ } if ($this->token !== self::TOK_TAG_CLOSE) { $this->addError('Expected ">", but found "'.$this->getTokenString().'"'); if ($this->next_pos('>', false) !== self::TOK_UNKNOWN) { $this->addError('No ">" tag found for "'.$this->status['tag_name'].'" tag'); return false; } } return true; }
php
{ "resource": "" }
q248765
HtmlParserBase.parse_all
validation
function parse_all() { $this->errors = array(); $this->status['last_pos'] = -1; if (($this->token === self::TOK_TAG_OPEN) || ($this->next_pos('<', false) === self::TOK_UNKNOWN)) { do { if (!$this->parse_tag()) { return false; } } while ($this->next_pos('<') !== self::TOK_NULL); } $this->pos = $this->size; $this->parse_text(); return true; }
php
{ "resource": "" }
q248766
HtmlParser.select
validation
function select($query = '*', $index = false, $recursive = true, $check_self = false) { return $this->root->select($query, $index, $recursive, $check_self); }
php
{ "resource": "" }
q248767
pQuery.parseFile
validation
public static function parseFile($path, $context = null) { $html_str = file_get_contents($path, false, $context); return static::parseStr($html_str); }
php
{ "resource": "" }
q248768
JSParser.nest
validation
private function nest($x, $node, $end = false) { array_push($x->stmtStack, $node); $n = $this->statement($x); array_pop($x->stmtStack); if ($end) $this->t->mustMatch($end); return $n; }
php
{ "resource": "" }
q248769
HtmlFormatter.minify_javascript
validation
static function minify_javascript(&$root, $indent_string = ' ', $wrap_comment = true, $recursive = true) { #php4 JSMin+ doesn't support PHP4 #return true; #php4e #php5 include_once('third party/jsminplus.php'); $errors = array(); foreach($root->select('script:not-empty > "~text~"', false, $recursive, true) as $c) { try { $text = $c->text; while ($text) { $text = trim($text); //Remove comment/CDATA tags at begin and end if (substr($text, 0, 4) === '<!--') { $text = substr($text, 5); continue; } elseif (strtolower(substr($text, 0, 9)) === '<![cdata[') { $text = substr($text, 10); continue; } if (($end = substr($text, -3)) && (($end === '-->') || ($end === ']]>'))) { $text = substr($text, 0, -3); continue; } break; } if (trim($text)) { $text = \JSMinPlus::minify($text); if ($wrap_comment) { $text = "<!--\n".$text."\n//-->"; } if ($indent_string && ($wrap_comment || (strpos($text, "\n") !== false))) { $text = indent_text("\n".$text, $c->indent(), $indent_string); } } $c->text = $text; } catch (\Exception $e) { $errors[] = array($e, $c->parent->dumpLocation()); } } return (($errors) ? $errors : true); #php5e }
php
{ "resource": "" }
q248770
DomNode.dumpLocation
validation
function dumpLocation() { return (($this->parent) ? (($p = $this->parent->dumpLocation()) ? $p.' > ' : '').$this->tag.'('.$this->typeIndex().')' : ''); }
php
{ "resource": "" }
q248771
DomNode.toString_attributes
validation
protected function toString_attributes() { $s = ''; foreach($this->attributes as $a => $v) { $s .= ' '.$a; if ((!$this->attribute_shorttag) || ($v !== $a)) { $quote = (strpos($v, '"') === false) ? '"' : "'"; $s .= '='.$quote.$v.$quote; } } return $s; }
php
{ "resource": "" }
q248772
DomNode.toString
validation
function toString($attributes = true, $recursive = true, $content_only = false) { if ($content_only) { if (is_int($content_only)) { --$content_only; } return $this->toString_content($attributes, $recursive, $content_only); } $s = '<'.$this->tag; if ($attributes) { $s .= $this->toString_attributes(); } if ($this->self_close) { $s .= $this->self_close_str.'>'; } else { $s .= '>'; if($recursive) { $s .= $this->toString_content($attributes); } $s .= '</'.$this->tag.'>'; } return $s; }
php
{ "resource": "" }
q248773
DomNode.html
validation
function html($value = null) { if ($value !== null) { $this->setInnerText($value); } return $this->getInnerText(); }
php
{ "resource": "" }
q248774
DomNode.setInnerText
validation
function setInnerText($text, $parser = null) { $this->clear(); if (trim($text)) { if ($parser === null) { $parser = new $this->parserClass(); } $parser->root =& $this; $parser->setDoc($text); $parser->parse_all(); } return (($parser && $parser->errors) ? $parser->errors : true); }
php
{ "resource": "" }
q248775
DomNode.getPlainTextUTF8
validation
function getPlainTextUTF8() { $txt = $this->toString(true, true, true); $enc = $this->getEncoding(); if ($enc !== false) { $txt = mb_convert_encoding($txt, 'UTF-8', $enc); } return preg_replace('`\s+`', ' ', html_entity_decode($txt, ENT_QUOTES, 'UTF-8')); }
php
{ "resource": "" }
q248776
DomNode.delete
validation
function delete() { if (($p = $this->parent) !== null) { $this->parent = null; $p->deleteChild($this); } else { $this->clear(); } }
php
{ "resource": "" }
q248777
DomNode.detach
validation
function detach($move_children_up = false) { if (($p = $this->parent) !== null) { $index = $this->index(); $this->parent = null; if ($move_children_up) { $this->moveChildren($p, $index); } $p->deleteChild($this, true); } }
php
{ "resource": "" }
q248778
DomNode.clear
validation
function clear() { foreach($this->children as $c) { $c->parent = null; $c->delete(); } $this->children = array(); }
php
{ "resource": "" }
q248779
DomNode.getRoot
validation
function getRoot() { $r = $this->parent; $n = ($r === null) ? null : $r->parent; while ($n !== null) { $r = $n; $n = $r->parent; } return $r; }
php
{ "resource": "" }
q248780
DomNode.isParent
validation
function isParent($tag, $recursive = false) { return ($this->hasParent($tag, $recursive) === ($tag !== null)); }
php
{ "resource": "" }
q248781
DomNode.index
validation
function index($count_all = true) { if (!$this->parent) { return -1; } elseif ($count_all) { return $this->parent->findChild($this); } else{ $index = -1; //foreach($this->parent->children as &$c) { // if (!$c->isTextOrComment()) { // ++$index; // } // if ($c === $this) { // return $index; // } //} foreach(array_keys($this->parent->children) as $k) { if (!$this->parent->children[$k]->isTextOrComment()) { ++$index; } if ($this->parent->children[$k] === $this) { return $index; } } return -1; } }
php
{ "resource": "" }
q248782
DomNode.setIndex
validation
function setIndex($index) { if ($this->parent) { if ($index > $this->index()) { --$index; } $this->delete(); $this->parent->addChild($this, $index); } }
php
{ "resource": "" }
q248783
DomNode.typeIndex
validation
function typeIndex() { if (!$this->parent) { return -1; } else { $index = -1; //foreach($this->parent->children as &$c) { // if (strcasecmp($this->tag, $c->tag) === 0) { // ++$index; // } // if ($c === $this) { // return $index; // } //} foreach(array_keys($this->parent->children) as $k) { if (strcasecmp($this->tag, $this->parent->children[$k]->tag) === 0) { ++$index; } if ($this->parent->children[$k] === $this) { return $index; } } return -1; } }
php
{ "resource": "" }
q248784
DomNode.getSibling
validation
function getSibling($offset = 1) { $index = $this->index() + $offset; if (($index >= 0) && ($index < $this->parent->childCount())) { return $this->parent->getChild($index); } else { return null; } }
php
{ "resource": "" }
q248785
DomNode.getNextSibling
validation
function getNextSibling($skip_text_comments = true) { $offset = 1; while (($n = $this->getSibling($offset)) !== null) { if ($skip_text_comments && ($n->tag[0] === '~')) { ++$offset; } else { break; } } return $n; }
php
{ "resource": "" }
q248786
DomNode.getNamespace
validation
function getNamespace() { if ($this->tag_ns === null) { $a = explode(':', $this->tag, 2); if (empty($a[1])) { $this->tag_ns = array('', $a[0]); } else { $this->tag_ns = array($a[0], $a[1]); } } return $this->tag_ns[0]; }
php
{ "resource": "" }
q248787
DomNode.setNamespace
validation
function setNamespace($ns) { if ($this->getNamespace() !== $ns) { $this->tag_ns[0] = $ns; $this->tag = $ns.':'.$this->tag_ns[1]; } }
php
{ "resource": "" }
q248788
DomNode.getEncoding
validation
function getEncoding() { $root = $this->getRoot(); if ($root !== null) { if ($enc = $root->select('meta[charset]', 0, true, true)) { return $enc->getAttribute("charset"); } elseif ($enc = $root->select('"?xml"[encoding]', 0, true, true)) { return $enc->getAttribute("encoding"); } elseif ($enc = $root->select('meta[content*="charset="]', 0, true, true)) { $enc = $enc->getAttribute("content"); return substr($enc, strpos($enc, "charset=")+8); } } return false; }
php
{ "resource": "" }
q248789
DomNode.childCount
validation
function childCount($ignore_text_comments = false) { if (!$ignore_text_comments) { return count($this->children); } else{ $count = 0; //foreach($this->children as &$c) { // if (!$c->isTextOrComment()) { // ++$count; // } //} foreach(array_keys($this->children) as $k) { if (!$this->children[$k]->isTextOrComment()) { ++$count; } } return $count; } }
php
{ "resource": "" }
q248790
DomNode.deleteChild
validation
function deleteChild($child, $soft_delete = false) { if (is_object($child)) { $child = $this->findChild($child); } elseif ($child < 0) { $child += count($this->children); } if (!$soft_delete) { $this->children[$child]->delete(); } unset($this->children[$child]); //Rebuild indices $tmp = array(); //foreach($this->children as &$c) { // $tmp[] =& $c; //} foreach(array_keys($this->children) as $k) { $tmp[] =& $this->children[$k]; } $this->children = $tmp; }
php
{ "resource": "" }
q248791
DomNode.wrapInner
validation
function wrapInner($node, $start = 0, $end = -1, $wrap_index = -1, $node_index = null) { if ($end < 0) { $end += count($this->children); } if ($node_index === null) { $node_index = $end + 1; } if (!is_object($node)) { $node = $this->addChild($node, $node_index); } elseif ($node->parent !== $this) { $node->changeParent($this->parent, $node_index); } $this->moveChildren($node, $wrap_index, $start, $end); return $node; }
php
{ "resource": "" }
q248792
DomNode.hasAttribute
validation
function hasAttribute($attr, $compare = 'total', $case_sensitive = false) { return ((bool) $this->findAttribute($attr, $compare, $case_sensitive)); }
php
{ "resource": "" }
q248793
DomNode.getChildrenByCallback
validation
function getChildrenByCallback($callback, $recursive = true, $check_self = false) { $count = $this->childCount(); if ($check_self && $callback($this)) { $res = array($this); } else { $res = array(); } if ($count > 0) { if (is_int($recursive)) { $recursive = (($recursive > 1) ? $recursive - 1 : false); } for ($i = 0; $i < $count; $i++) { if ($callback($this->children[$i])) { $res[] = $this->children[$i]; } if ($recursive) { $res = array_merge($res, $this->children[$i]->getChildrenByCallback($callback, $recursive)); } } } return $res; }
php
{ "resource": "" }
q248794
DomNode.match_tags
validation
protected function match_tags($tags) { $res = false; foreach($tags as $tag => $match) { if (!is_array($match)) { $match = array( 'match' => $match, 'operator' => 'or', 'compare' => 'total', 'case_sensitive' => false ); } else { if (is_int($tag)) { $tag = $match['tag']; } if (!isset($match['match'])) { $match['match'] = true; } if (!isset($match['operator'])) { $match['operator'] = 'or'; } if (!isset($match['compare'])) { $match['compare'] = 'total'; } if (!isset($match['case_sensitive'])) { $match['case_sensitive'] = false; } } if (($match['operator'] === 'and') && (!$res)) { return false; } elseif (!($res && ($match['operator'] === 'or'))) { if ($match['compare'] === 'total') { $a = $this->tag; } elseif ($match['compare'] === 'namespace') { $a = $this->getNamespace(); } elseif ($match['compare'] === 'name') { $a = $this->getTag(); } if ($match['case_sensitive']) { $res = (($a === $tag) === $match['match']); } else { $res = ((strcasecmp($a, $tag) === 0) === $match['match']); } } } return $res; }
php
{ "resource": "" }
q248795
DomNode.match_filters
validation
protected function match_filters($conditions, $custom_filters = array()) { foreach($conditions as $c) { $c['filter'] = strtolower($c['filter']); if (isset($this->filter_map[$c['filter']])) { if (!$this->{$this->filter_map[$c['filter']]}($c['params'])) { return false; } } elseif (isset($custom_filters[$c['filter']])) { if (!call_user_func($custom_filters[$c['filter']], $this, $c['params'])) { return false; } } else { trigger_error('Unknown filter "'.$c['filter'].'"!'); return false; } } return true; }
php
{ "resource": "" }
q248796
DomNode.match
validation
function match($conditions, $match = true, $custom_filters = array()) { $t = isset($conditions['tags']); $a = isset($conditions['attributes']); $f = isset($conditions['filters']); if (!($t || $a || $f)) { if (is_array($conditions) && $conditions) { foreach($conditions as $c) { if ($this->match($c, $match)) { return true; } } } return false; } else { if (($t && (!$this->match_tags($conditions['tags']))) === $match) { return false; } if (($a && (!$this->match_attributes($conditions['attributes']))) === $match) { return false; } if (($f && (!$this->match_filters($conditions['filters'], $custom_filters))) === $match) { return false; } return true; } }
php
{ "resource": "" }
q248797
DomNode.getChildrenByAttribute
validation
function getChildrenByAttribute($attribute, $value, $mode = 'equals', $compare = 'total', $recursive = true) { if ($this->childCount() < 1) { return array(); } $mode = explode(' ', strtolower($mode)); $match = ((isset($mode[1]) && ($mode[1] === 'not')) ? 'false' : 'true'); return $this->getChildrenByMatch( array( 'attributes' => array( $attribute => array( 'operator_value' => $mode[0], 'value' => $value, 'match' => $match, 'compare' => $compare ) ) ), $recursive ); }
php
{ "resource": "" }
q248798
DomNode.getChildrenByTag
validation
function getChildrenByTag($tag, $compare = 'total', $recursive = true) { if ($this->childCount() < 1) { return array(); } $tag = explode(' ', strtolower($tag)); $match = ((isset($tag[1]) && ($tag[1] === 'not')) ? 'false' : 'true'); return $this->getChildrenByMatch( array( 'tags' => array( $tag[0] => array( 'match' => $match, 'compare' => $compare ) ) ), $recursive ); }
php
{ "resource": "" }
q248799
DomNode.query
validation
public function query($query = '*') { $select = $this->select($query); $result = new \pQuery((array)$select); return $result; }
php
{ "resource": "" }