_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q248800
DomNode.select
validation
function select($query = '*', $index = false, $recursive = true, $check_self = false) { $s = new $this->selectClass($this, $query, $check_self, $recursive); $res = $s->result; unset($s); if (is_array($res) && ($index === true) && (count($res) === 1)) { return $res[0]; } elseif (is_int($index) && is_array($res)) { if ($index < 0) { $index += count($res); } return ($index < count($res)) ? $res[$index] : null; } else { return $res; } }
php
{ "resource": "" }
q248801
CSSQueryTokenizer.parse_gt
validation
protected function parse_gt() { if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === '=')) { ++$this->pos; return ($this->token = self::TOK_COMPARE_BIGGER_THAN); } else { return ($this->token = self::TOK_CHILD); } }
php
{ "resource": "" }
q248802
CSSQueryTokenizer.parse_sibling
validation
protected function parse_sibling() { if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === '=')) { ++$this->pos; return ($this->token = self::TOK_COMPARE_CONTAINS_WORD); } else { return ($this->token = self::TOK_SIBLING); } }
php
{ "resource": "" }
q248803
CSSQueryTokenizer.parse_pipe
validation
protected function parse_pipe() { if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === '=')) { ++$this->pos; return ($this->token = self::TOK_COMPARE_PREFIX); } else { return ($this->token = self::TOK_PIPE); } }
php
{ "resource": "" }
q248804
CSSQueryTokenizer.parse_not
validation
protected function parse_not() { if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === '=')) { ++$this->pos; return ($this->token = self::TOK_COMPARE_NOT_EQUAL); } else { return ($this->token = self::TOK_NOT); } }
php
{ "resource": "" }
q248805
CSSQueryTokenizer.parse_compare
validation
protected function parse_compare() { if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === '=')) { switch($this->doc[$this->pos++]) { case '$': return ($this->token = self::TOK_COMPARE_ENDS); case '%': return ($this->token = self::TOK_COMPARE_REGEX); case '^': return ($this->token = self::TOK_COMPARE_STARTS); case '<': return ($this->token = self::TOK_COMPARE_SMALLER_THAN); } } return false; }
php
{ "resource": "" }
q248806
HtmlSelector.parse_callback
validation
protected function parse_callback($conditions, $recursive = true, $check_root = false) { return ($this->result = $this->root->getChildrenByMatch( $conditions, $recursive, $check_root, $this->custom_filter_map )); }
php
{ "resource": "" }
q248807
HtmlSelector.parse_single
validation
protected function parse_single($recursive = true) { if (($c = $this->parse_conditions()) === false) { return false; } $this->parse_callback($c, $recursive, $this->search_root); return true; }
php
{ "resource": "" }
q248808
HtmlSelector.parse_adjacent
validation
protected function parse_adjacent() { $tmp = $this->result; $this->result = array(); if (($c = $this->parse_conditions()) === false) { return false; } foreach($tmp as $t) { if (($sibling = $t->getNextSibling()) !== false) { if ($sibling->match($c, true, $this->custom_filter_map)) { $this->result[] = $sibling; } } } return true; }
php
{ "resource": "" }
q248809
HtmlSelector.parse
validation
protected function parse() { $p =& $this->parser; $p->setPos(0); $this->result = array(); if (!$this->parse_single()) { return false; } while (count($this->result) > 0) { switch($p->token) { case CSSQueryTokenizer::TOK_CHILD: $this->parser->next_no_whitespace(); if (!$this->parse_result(false, 1)) { return false; } break; case CSSQueryTokenizer::TOK_SIBLING: $this->parser->next_no_whitespace(); if (!$this->parse_result(true, 1)) { return false; } break; case CSSQueryTokenizer::TOK_PLUS: $this->parser->next_no_whitespace(); if (!$this->parse_adjacent()) { return false; } break; case CSSQueryTokenizer::TOK_ALL: case CSSQueryTokenizer::TOK_IDENTIFIER: case CSSQueryTokenizer::TOK_STRING: case CSSQueryTokenizer::TOK_BRACE_OPEN: case CSSQueryTokenizer::TOK_BRACKET_OPEN: case CSSQueryTokenizer::TOK_ID: case CSSQueryTokenizer::TOK_CLASS: case CSSQueryTokenizer::TOK_COLON: if (!$this->parse_result()) { return false; } break; case CSSQueryTokenizer::TOK_NULL: break 2; default: $this->error('Invalid search pattern(3): No result modifier found!'); return false; } } return true; }
php
{ "resource": "" }
q248810
GreenhouseService.getJobApiService
validation
public function getJobApiService() { $apiService = new \Greenhouse\GreenhouseToolsPhp\Services\JobApiService($this->_boardToken); $apiClient = new GuzzleClient(array( 'base_uri' => ApiService::jobBoardBaseUrl($this->_boardToken) )); $apiService->setClient($apiClient); return $apiService; }
php
{ "resource": "" }
q248811
GreenhouseService.getApplicationApiService
validation
public function getApplicationApiService() { $applicationService = new \Greenhouse\GreenhouseToolsPhp\Services\ApplicationService($this->_apiKey, $this->_boardToken); $apiClient = new GuzzleClient(array( 'base_uri' => ApiService::APPLICATION_URL )); $applicationService->setClient($apiClient); return $applicationService; }
php
{ "resource": "" }
q248812
GuzzleClient.get
validation
public function get($url="") { try { $this->guzzleResponse = $this->_client->request('GET', $url); $this->_setLinks(); } catch (RequestException $e) { throw new GreenhouseAPIResponseException($e->getMessage(), 0, $e); } /** * Just return the response cast as a string. The rest of the universe need * not be aware of Guzzle's details. */ return (string) $this->guzzleResponse->getBody(); }
php
{ "resource": "" }
q248813
GuzzleClient.post
validation
public function post(Array $postVars, Array $headers, $url=null) { try { $this->guzzleResponse = $this->_client->request( 'POST', $url, array('multipart' => $postVars, 'headers' => $headers) ); } catch (RequestException $e) { throw new GreenhouseAPIResponseException($e->getMessage(), 0, $e); } return (string) $this->guzzleResponse->getBody(); }
php
{ "resource": "" }
q248814
ApplicationService.validateRequiredFields
validation
public function validateRequiredFields($postVars) { $requiredFields = $this->getRequiredFields($postVars['id']); $missingKeys = array(); foreach ($requiredFields as $human => $keys) { if (!$this->hasRequiredValue($postVars, $keys)) { $missingKeys[] = $human; } } if (!empty($missingKeys)) { throw new GreenhouseApplicationException('Submission missing required answers for: ' . implode(', ', $missingKeys)); } return true; }
php
{ "resource": "" }
q248815
ApplicationService.hasRequiredValue
validation
public function hasRequiredValue($postVars, $keys) { foreach ($keys as $key) { $requiredKey = $this->findKey($key, $postVars); if (array_key_exists($requiredKey, $postVars) && $postVars[$requiredKey] !== '') return true; } return false; }
php
{ "resource": "" }
q248816
HarvestService.getCustomFields
validation
public function getCustomFields($parameters=array()) { $this->_harvest = $this->_harvestHelper->parse('getCustomFields', $parameters); if (!array_key_exists('id', $parameters)) $this->_harvest['url'] = $this->_harvest['url'] . '/'; $this->sendRequest(); }
php
{ "resource": "" }
q248817
ModuleRecordFileField.configureData
validation
protected function configureData($data) { if (is_string($data)) { if (!empty($this->Options)) { $fileField = end($this->Options); $data = array( $fileField => $data ); } else { throw new RequiredOptionsException(get_called_class(), "Options are required, when passing String for data."); } } if (is_array($data)) { foreach ($data as $key => $value) { if (!array_key_exists($key, $this->_REQUIRED_DATA)) { $data[$key] = $this->setFileFieldValue($value); } } } parent::configureData($data); }
php
{ "resource": "" }
q248818
ModuleRecordFileField.setFileFieldValue
validation
protected function setFileFieldValue($value) { if (version_compare(PHP_VERSION, '5.5.0') >= 0){ if (!($value instanceof \CURLFile)){ $value = ltrim($value,"@"); $value = new \CURLFile($value); } } else { if (strpos($value, '@') !== 0) { $value = '@'.$value; } } return $value; }
php
{ "resource": "" }
q248819
AbstractEndpoint.configureData
validation
protected function configureData($data) { if (!empty($this->_REQUIRED_DATA)&&is_array($data)) { $data = $this->configureDefaultData($data); } $this->setData($data); }
php
{ "resource": "" }
q248820
AbstractEndpoint.configureDefaultData
validation
protected function configureDefaultData(array $data) { foreach ($this->_REQUIRED_DATA as $property => $value) { if (!isset($data[$property]) && $value !== null) { $data[$property] = $value; } } return $data; }
php
{ "resource": "" }
q248821
AbstractEndpoint.verifyUrl
validation
protected function verifyUrl() { $UrlArray = explode("?", $this->Url); if (strpos($UrlArray[0], "$") !== false) { throw new InvalidURLException(get_called_class(), "Configured URL is ".$this->Url); } return true; }
php
{ "resource": "" }
q248822
AbstractEndpoint.verifyData
validation
protected function verifyData() { if (isset($this->_DATA_TYPE) || !empty($this->_DATA_TYPE)) { $this->verifyDataType(); } if (!empty($this->_REQUIRED_DATA)) { $this->verifyRequiredData(); } return true; }
php
{ "resource": "" }
q248823
AbstractEndpoint.verifyRequiredData
validation
protected function verifyRequiredData() { $errors = array(); foreach ($this->_REQUIRED_DATA as $property => $defaultValue) { if ((!isset($this->Data[$property])) && empty($defaultValue)) { $errors[] = $property; } } if (count($errors) > 0) { throw new RequiredDataException(get_called_class(), "Missing data for ".implode(",", $errors)); } return true; }
php
{ "resource": "" }
q248824
AbstractResponse.extractInfo
validation
protected function extractInfo() { $this->info = curl_getinfo($this->CurlRequest); $this->status = $this->info['http_code']; if (curl_errno($this->CurlRequest)!== CURLE_OK) { $this->error = curl_error($this->CurlRequest); } else { $this->error = false; } }
php
{ "resource": "" }
q248825
AbstractResponse.extractResponse
validation
protected function extractResponse($curlResponse) { $this->headers = substr($curlResponse, 0, $this->info['header_size']); $this->body = substr($curlResponse, $this->info['header_size']); }
php
{ "resource": "" }
q248826
Helpers.getSDKEndpointRegistry
validation
public static function getSDKEndpointRegistry() { $entryPoints = array(); require __DIR__.DIRECTORY_SEPARATOR.'registry.php'; foreach ($entryPoints as $funcName => $className) { $className = "SugarAPI\\SDK\\Endpoint\\" . $className; $entryPoints[$funcName] = $className; } return $entryPoints; }
php
{ "resource": "" }
q248827
File.setDestinationPath
validation
public function setDestinationPath($destination = null) { if (empty($destination)) { $destination = sys_get_temp_dir().'/SugarAPI'; } $this->destinationPath = $destination; return $this; }
php
{ "resource": "" }
q248828
File.extractFileName
validation
protected function extractFileName(){ foreach (explode("\r\n", $this->headers) as $header) { if (strpos($header, 'filename') !== false && strpos($header, 'Content-Disposition') !== false) { $fileName = substr($header, (strpos($header, "=")+1)); $this->setFileName($fileName); break; } } }
php
{ "resource": "" }
q248829
File.setFileName
validation
public function setFileName($fileName) { $fileName = preg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $fileName); $fileName = preg_replace("([\.]{2,})", '', $fileName); $this->fileName = $fileName; return $this; }
php
{ "resource": "" }
q248830
AbstractRequest.configureType
validation
protected function configureType() { switch ($this->type) { case 'POST': $this->setOption(CURLOPT_POST, true); break; case 'DELETE': case 'PUT': $this->setOption(CURLOPT_CUSTOMREQUEST, $this->type); break; } }
php
{ "resource": "" }
q248831
TwbBundleFormCollection.renderTemplate
validation
public function renderTemplate(CollectionElement $collection) { if (false != ($sElementLayout = $collection->getOption('twb-layout'))) { $elementOrFieldset = $collection->getTemplateElement(); $elementOrFieldset->setOption('twb-layout', $sElementLayout); } return parent::renderTemplate($collection); }
php
{ "resource": "" }
q248832
TwbBundleBadge.render
validation
public function render($sBadgeMessage, array $aBadgeAttributes = null) { if (!is_scalar($sBadgeMessage)) { throw new InvalidArgumentException(sprintf( 'Badge message expects a scalar value, "%s" given', is_object($sBadgeMessage) ? get_class($sBadgeMessage) : gettype($sBadgeMessage) )); } if (empty($aBadgeAttributes)) { $aBadgeAttributes = array('class' => 'badge'); } else { if (empty($aBadgeAttributes['class'])) { $aBadgeAttributes['class'] = 'badge'; } elseif (!preg_match('/(\s|^)badge(\s|$)/', $aBadgeAttributes['class'])) { $aBadgeAttributes['class'] .= ' badge'; } } if (null !== ($oTranslator = $this->getTranslator())) { $sBadgeMessage = $oTranslator->translate($sBadgeMessage, $this->getTranslatorTextDomain()); } return sprintf( static::$badgeFormat, $this->createAttributesString($aBadgeAttributes), $sBadgeMessage ); }
php
{ "resource": "" }
q248833
TwbBundleForm.setFormClass
validation
protected function setFormClass(FormInterface $oForm, $sFormLayout = self::LAYOUT_HORIZONTAL) { if (is_string($sFormLayout)) { $sLayoutClass = 'form-' . $sFormLayout; if ($sFormClass = $oForm->getAttribute('class')) { if (!preg_match('/(\s|^)' . preg_quote($sLayoutClass, '/') . '(\s|$)/', $sFormClass)) { $oForm->setAttribute('class', trim($sFormClass . ' ' . $sLayoutClass)); } } else { $oForm->setAttribute('class', $sLayoutClass); } } return $this; }
php
{ "resource": "" }
q248834
TwbBundleForm.openTag
validation
public function openTag(FormInterface $form = null) { $this->setFormClass($form, $this->formLayout); return parent::openTag($form); }
php
{ "resource": "" }
q248835
TwbBundleLabel.render
validation
public function render($sLabelMessage, $aLabelAttributes = 'label-default') { if (!is_scalar($sLabelMessage)) { throw new InvalidArgumentException('Label message expects a scalar value, "' . gettype($sLabelMessage) . '" given'); } if (empty($aLabelAttributes)) { throw new InvalidArgumentException('Label attributes are empty'); } if (is_string($aLabelAttributes)) { $aLabelAttributes = array('class' => $aLabelAttributes); } elseif (!is_array($aLabelAttributes)) { throw new InvalidArgumentException('Label attributes expects a string or an array, "' . gettype($aLabelAttributes) . '" given'); } elseif (empty($aLabelAttributes['class'])) { throw new \InvalidArgumentException('Label "class" attribute is empty'); } elseif (!is_string($aLabelAttributes['class'])) { throw new InvalidArgumentException('Label "class" attribute expects string, "' . gettype($aLabelAttributes) . '" given'); } if (!preg_match('/(\s|^)label(\s|$)/', $aLabelAttributes['class'])) { $aLabelAttributes['class'] .= ' label'; } if (null !== ($oTranslator = $this->getTranslator())) { $sLabelMessage = $oTranslator->translate($sLabelMessage, $this->getTranslatorTextDomain()); } return sprintf( static::$labelFormat, isset($aLabelAttributes['tagName']) ? $aLabelAttributes['tagName'] : $this->tagName, $this->createAttributesString($aLabelAttributes), $sLabelMessage ); }
php
{ "resource": "" }
q248836
TwbBundleFormRow.renderLabel
validation
protected function renderLabel(ElementInterface $oElement) { if (($sLabel = $oElement->getLabel()) && ($oTranslator = $this->getTranslator())) { $sLabel = $oTranslator->translate($sLabel, $this->getTranslatorTextDomain()); } return $sLabel; }
php
{ "resource": "" }
q248837
TwbBundleFormRow.renderHelpBlock
validation
protected function renderHelpBlock(ElementInterface $oElement) { if ($sHelpBlock = $oElement->getOption('help-block')) { if ($oTranslator = $this->getTranslator()) { $sHelpBlock = $oTranslator->translate($sHelpBlock, $this->getTranslatorTextDomain()); } $sHelpBlockString = strip_tags($sHelpBlock); if ($sHelpBlock === $sHelpBlockString) { $sHelpBlock = $this->getEscapeHtmlHelper()->__invoke($sHelpBlock); } return sprintf(static::$helpBlockFormat, $sHelpBlock); } else { return ''; } }
php
{ "resource": "" }
q248838
TwbBundleFontAwesome.render
validation
public function render($sFontAwesome, array $aFontAwesomeAttributes = null) { if (!is_scalar($sFontAwesome)) { throw new \InvalidArgumentException( sprintf( 'FontAwesome expects a scalar value, "%s" given', gettype($sFontAwesome) ) ); } if (empty($aFontAwesomeAttributes)) { $aFontAwesomeAttributes = array('class' => 'fa'); } else { if (empty($aFontAwesomeAttributes['class'])) { $aFontAwesomeAttributes['class'] = 'fa'; } elseif (!preg_match('/(\s|^)fa(\s|$)/', $aFontAwesomeAttributes['class'])) { $aFontAwesomeAttributes['class'] .= ' fa'; } } if (strpos('fa-', $sFontAwesome) !== 0) { $sFontAwesome = 'fa-' . $sFontAwesome; } if (!preg_match('/(\s|^)' . preg_quote($sFontAwesome, '/') . '(\s|$)/', $aFontAwesomeAttributes['class'])) { $aFontAwesomeAttributes['class'] .= ' ' . $sFontAwesome; } return sprintf( static::$faFormat, $this->createAttributesString($aFontAwesomeAttributes) ); }
php
{ "resource": "" }
q248839
TwbBundleGlyphicon.render
validation
public function render($sGlyphicon, array $aGlyphiconAttributes = null) { if (!is_scalar($sGlyphicon)) { throw new InvalidArgumentException('Glyphicon expects a scalar value, "' . gettype($sGlyphicon) . '" given'); } if (empty($aGlyphiconAttributes)) { $aGlyphiconAttributes = array('class' => 'glyphicon'); } else { if (empty($aGlyphiconAttributes['class'])) { $aGlyphiconAttributes['class'] = 'glyphicon'; } elseif (!preg_match('/(\s|^)glyphicon(\s|$)/', $aGlyphiconAttributes['class'])) { $aGlyphiconAttributes['class'] .= ' glyphicon'; } } if (strpos('glyphicon-', $sGlyphicon) !== 0) { $sGlyphicon = 'glyphicon-' . $sGlyphicon; } if (!preg_match('/(\s|^)' . preg_quote($sGlyphicon, '/') . '(\s|$)/', $aGlyphiconAttributes['class'])) { $aGlyphiconAttributes['class'] .= ' ' . $sGlyphicon; } return sprintf( static::$glyphiconFormat, $this->createAttributesString($aGlyphiconAttributes) ); }
php
{ "resource": "" }
q248840
TwbBundleAlert.render
validation
public function render($sAlertMessage, $aAlertAttributes = null, $bDismissable = false) { if (!is_scalar($sAlertMessage)) { throw new InvalidArgumentException('Alert message expects a scalar value, "' . gettype($sAlertMessage) . '" given'); } if (empty($aAlertAttributes)) { $aAlertAttributes = array('class' => 'alert'); } elseif (is_string($aAlertAttributes)) { $aAlertAttributes = array('class' => $aAlertAttributes); } elseif (!is_array($aAlertAttributes)) { throw new InvalidArgumentException('Alert attributes expects a string or an array, "' . gettype($aAlertAttributes) . '" given'); } elseif (empty($aAlertAttributes['class'])) { throw new InvalidArgumentException('Alert "class" attribute is empty'); } elseif (!is_string($aAlertAttributes['class'])) { throw new InvalidArgumentException('Alert "class" attribute expects string, "' . gettype($aAlertAttributes) . '" given'); } if (!preg_match('/(\s|^)alert(\s|$)/', $aAlertAttributes['class'])) { $aAlertAttributes['class'] .= ' alert'; } if (null !== ($oTranslator = $this->getTranslator())) { $sAlertMessage = $oTranslator->translate($sAlertMessage, $this->getTranslatorTextDomain()); } if ($bDismissable) { $sAlertMessage = static::$dismissButtonFormat . $sAlertMessage; if (!preg_match('/(\s|^)alert-dismissable(\s|$)/', $aAlertAttributes['class'])) { $aAlertAttributes['class'] .= ' alert-dismissable'; } } return sprintf( static::$alertFormat, $this->createAttributesString($aAlertAttributes), $sAlertMessage ); }
php
{ "resource": "" }
q248841
TwbBundleButtonGroup.render
validation
public function render(array $aButtons, array $aButtonGroupOptions = null) { /* * Button group container attributes */ if (empty($aButtonGroupOptions['attributes'])) { $aButtonGroupOptions['attributes'] = array('class' => 'btn-group'); } else { if (!is_array($aButtonGroupOptions['attributes'])) { throw new LogicException('"attributes" option expects an array, "' . gettype($aButtonGroupOptions['attributes']) . '" given'); } if (empty($aButtonGroupOptions['attributes']['class'])) { $aButtonGroupOptions['attributes']['class'] = 'btn-group'; } elseif (!preg_match('/(\s|^)(?:btn-group|btn-group-vertical)(\s|$)/', $aButtonGroupOptions['attributes']['class'])) { $aButtonGroupOptions['attributes']['class'] .= ' btn-group'; } } /* * Render button group */ return sprintf( static::$buttonGroupContainerFormat, //Container attributes $this->createAttributesString($aButtonGroupOptions['attributes']), //Buttons $this->renderButtons( $aButtons, strpos($aButtonGroupOptions['attributes']['class'], 'btn-group-justified') !== false ) ); }
php
{ "resource": "" }
q248842
TwbBundleButtonGroup.renderButtons
validation
protected function renderButtons(array $aButtons, $bJustified = false) { $sMarkup = ''; foreach ($aButtons as $oButton) { if (is_array($oButton) || ($oButton instanceof Traversable && !($oButton instanceof ElementInterface)) ) { $oFactory = new Factory(); $oButton = $oFactory->create($oButton); } elseif (!($oButton instanceof ElementInterface)) { throw new LogicException(sprintf( 'Button expects an instanceof Zend\Form\ElementInterface or an array / Traversable, "%s" given', is_object($oButton) ? get_class($oButton) : gettype($oButton) )); } $sButtonMarkup = $this->getFormElementHelper()->__invoke($oButton); $sMarkup .= $bJustified ? sprintf(static::$buttonGroupJustifiedFormat, $sButtonMarkup) : $sButtonMarkup; } return $sMarkup; }
php
{ "resource": "" }
q248843
TwbBundleFormErrors.render
validation
public function render(FormInterface $oForm, $sMessage, $bDismissable = false) { $errorHtml = sprintf($this->messageOpenFormat, $sMessage); $sMessagesArray = array(); foreach ($oForm->getMessages() as $fieldName => $sMessages) { foreach ($sMessages as $sMessage) { if ($oForm->get($fieldName)->getAttribute('id')) { $sMessagesArray[] = sprintf( '<a href="#%s">%s</a>', $oForm->get($fieldName)->getAttribute('id'), $oForm->get($fieldName)->getLabel() . ': ' . $sMessage ); } else { $sMessagesArray[] = $oForm->get($fieldName)->getLabel() . ': ' . $sMessage; } } } return $this->dangerAlert( $errorHtml . implode($this->messageSeparatorString, $sMessagesArray) . $this->messageCloseString, $bDismissable ); }
php
{ "resource": "" }
q248844
TwbBundleFormElement.render
validation
public function render(ElementInterface $oElement) { // Add form-controll class $sElementType = $oElement->getAttribute('type'); if (!in_array($sElementType, $this->options->getIgnoredViewHelpers()) && !($oElement instanceof Collection) ) { if ($sElementClass = $oElement->getAttribute('class')) { if (!preg_match('/(\s|^)form-control(\s|$)/', $sElementClass)) { $oElement->setAttribute('class', trim($sElementClass . ' form-control')); } } else { $oElement->setAttribute('class', 'form-control'); } } $sMarkup = parent::render($oElement); // Addon prepend if ($aAddOnPrepend = $oElement->getOption('add-on-prepend')) { $sMarkup = $this->renderAddOn($aAddOnPrepend) . $sMarkup; } // Addon append if ($aAddOnAppend = $oElement->getOption('add-on-append')) { $sMarkup .= $this->renderAddOn($aAddOnAppend); } if ($aAddOnAppend || $aAddOnPrepend) { $sSpecialClass = ''; // Input size if ($sElementClass = $oElement->getAttribute('class')) { if (preg_match('/(\s|^)input-lg(\s|$)/', $sElementClass)) { $sSpecialClass .= ' input-group-lg'; } elseif (preg_match('/(\s|^)input-sm(\s|$)/', $sElementClass)) { $sSpecialClass .= ' input-group-sm'; } } return sprintf( static::$inputGroupFormat, trim($sSpecialClass), $sMarkup ); } return $sMarkup; }
php
{ "resource": "" }
q248845
TwbBundleFormElement.renderAddOn
validation
protected function renderAddOn($aAddOnOptions) { if (empty($aAddOnOptions)) { throw new InvalidArgumentException('Addon options are empty'); } if ($aAddOnOptions instanceof ElementInterface) { $aAddOnOptions = array('element' => $aAddOnOptions); } elseif (is_scalar($aAddOnOptions)) { $aAddOnOptions = array('text' => $aAddOnOptions); } elseif (!is_array($aAddOnOptions)) { throw new InvalidArgumentException(sprintf( 'Addon options expects an array or a scalar value, "%s" given', is_object($aAddOnOptions) ? get_class($aAddOnOptions) : gettype($aAddOnOptions) )); } $sMarkup = ''; $sAddonTagName = 'span'; $sAddonClass = ''; if (!empty($aAddOnOptions['text'])) { if (!is_scalar($aAddOnOptions['text'])) { throw new InvalidArgumentException(sprintf( '"text" option expects a scalar value, "%s" given', is_object($aAddOnOptions['text']) ? get_class($aAddOnOptions['text']) : gettype($aAddOnOptions['text']) )); } elseif (($oTranslator = $this->getTranslator())) { $sMarkup .= $oTranslator->translate($aAddOnOptions['text'], $this->getTranslatorTextDomain()); } else { $sMarkup .= $aAddOnOptions['text']; } $sAddonClass .= ' input-group-addon'; } elseif (!empty($aAddOnOptions['element'])) { if (is_array($aAddOnOptions['element']) || ($aAddOnOptions['element'] instanceof Traversable && !($aAddOnOptions['element'] instanceof ElementInterface)) ) { $oFactory = new Factory(); $aAddOnOptions['element'] = $oFactory->create($aAddOnOptions['element']); } elseif (!($aAddOnOptions['element'] instanceof ElementInterface)) { throw new LogicException(sprintf( '"element" option expects an instanceof Zend\Form\ElementInterface, "%s" given', is_object($aAddOnOptions['element']) ? get_class($aAddOnOptions['element']) : gettype($aAddOnOptions['element']) )); } $aAddOnOptions['element']->setOptions(array_merge( $aAddOnOptions['element']->getOptions(), array('disable-twb' => true) )); $sMarkup .= $this->render($aAddOnOptions['element']); //Element is a button, so add-on container must be a "div" if ($aAddOnOptions['element'] instanceof Button) { $sAddonClass .= ' input-group-btn'; $sAddonTagName = 'div'; } else { $sAddonClass .= ' input-group-addon'; } } return sprintf(static::$addonFormat, $sAddonTagName, trim($sAddonClass), $sMarkup, $sAddonTagName); }
php
{ "resource": "" }
q248846
TwbBundleFormElement.setTranslator
validation
public function setTranslator(TranslatorInterface $oTranslator = null, $sTextDomain = null) { $this->translator = $oTranslator; if (null !== $sTextDomain) { $this->setTranslatorTextDomain($sTextDomain); } return $this; }
php
{ "resource": "" }
q248847
TwbBundleDropDown.render
validation
public function render(array $aDropdownOptions) { // Dropdown container attributes if (empty($aDropdownOptions['attributes'])) { $aDropdownOptions['attributes'] = array('class' => 'dropdown'); } else { if (!is_array($aDropdownOptions['attributes'])) { throw new LogicException('"attributes" option expects an array, "' . gettype($aDropdownOptions['attributes']) . '" given'); } if (empty($aDropdownOptions['attributes']['class'])) { $aDropdownOptions['attributes']['class'] = 'dropdown'; } elseif (!preg_match('/(\s|^)dropdown(\s|$)/', $aDropdownOptions['attributes']['class'])) { $aDropdownOptions['attributes']['class'] .= ' dropdown'; } } // Render dropdown return sprintf( static::$dropdownContainerFormat, $this->createAttributesString($aDropdownOptions['attributes']), //Container attributes $this->renderToggle($aDropdownOptions) . //Toggle $this->renderListItems($aDropdownOptions) //List items ); }
php
{ "resource": "" }
q248848
TwbBundleDropDown.renderToggle
validation
public function renderToggle(array $aDropdownOptions) { // Dropdown toggle if (empty($aDropdownOptions['label'])) { $aDropdownOptions['label'] = ''; } elseif (!is_scalar($aDropdownOptions['label'])) { throw new InvalidArgumentException('"label" option expects a scalar value, "' . gettype($aDropdownOptions['label']) . '" given'); } elseif (($oTranslator = $this->getTranslator())) { $aDropdownOptions['label'] = $oTranslator->translate($aDropdownOptions['label'], $this->getTranslatorTextDomain()); } // Dropdown toggle attributes (class) if (empty($aDropdownOptions['toggle_attributes'])) { $aDropdownOptions['toggle_attributes'] = array('class' => 'sr-only dropdown-toggle'); } else { if (!is_array($aDropdownOptions['toggle_attributes'])) { throw new InvalidArgumentException('"toggle_attributes" option expects an array, "' . gettype($aDropdownOptions['toggle_attributes']) . '" given'); } if (empty($aDropdownOptions['toggle_attributes']['class'])) { $aDropdownOptions['toggle_attributes']['class'] = 'sr-only dropdown-toggle'; } else { if (!preg_match('/(\s|^)sr-only(\s|$)/', $aDropdownOptions['toggle_attributes']['class'])) { $aDropdownOptions['toggle_attributes']['class'] .= ' sr-only'; } if (!preg_match('/(\s|^)dropdown-toggle(\s|$)/', $aDropdownOptions['toggle_attributes']['class'])) { $aDropdownOptions['toggle_attributes']['class'] .= ' dropdown-toggle'; } } } // Dropdown toggle attributes (data-toggle) if (empty($aDropdownOptions['toggle_attributes']['data-toggle'])) { $aDropdownOptions['toggle_attributes']['data-toggle'] = 'dropdown'; } // Dropdown toggle attributes (role) if (empty($aDropdownOptions['toggle_attributes']['role'])) { $aDropdownOptions['toggle_attributes']['role'] = 'button'; } // Dropdown toggle attributes (href) if (empty($aDropdownOptions['toggle_attributes']['href'])) { $aDropdownOptions['toggle_attributes']['href'] = '#'; } // Dropdown toggle attributes (id) if (!empty($aDropdownOptions['name'])) { $aDropdownOptions['toggle_attributes']['id'] = $aDropdownOptions['name']; } $aValidTagAttributes = $this->validTagAttributes; $this->validTagAttributes = array('href' => true); $sAttributeString = $this->createAttributesString($aDropdownOptions['toggle_attributes']); $this->validTagAttributes = $aValidTagAttributes; return sprintf( static::$dropdownToggleFormat, $sAttributeString, // Toggle attributes $this->getEscapeHtmlHelper()->__invoke($aDropdownOptions['label']) // Toggle label ); }
php
{ "resource": "" }
q248849
TwbBundleDropDown.renderListItems
validation
public function renderListItems(array $aDropdownOptions) { if (!isset($aDropdownOptions['items'])) { throw new LogicException(__METHOD__ . ' expects "items" option'); } if (!is_array($aDropdownOptions['items'])) { throw new LogicException('"items" option expects an array, "' . gettype($aDropdownOptions['items']) . '" given'); } // Dropdown list attributes (class) if (empty($aDropdownOptions['list_attributes'])) { $aDropdownOptions['list_attributes'] = array('class' => 'dropdown-menu'); } else { if (!is_array($aDropdownOptions['list_attributes'])) { throw new \LogicException('"list_attributes" option expects an array, "' . gettype($aDropdownOptions['list_attributes']) . '" given'); } if (empty($aDropdownOptions['list_attributes']['class'])) { $aDropdownOptions['list_attributes']['class'] = 'dropdown-menu'; } elseif (!preg_match('/(\s|^)dropdown-menu(\s|$)/', $aDropdownOptions['list_attributes']['class'])) { $aDropdownOptions['list_attributes']['class'] .= ' dropdown-menu'; } } // Dropdown list attributes (role) if (empty($aDropdownOptions['list_attributes']['role'])) { $aDropdownOptions['list_attributes']['role'] = 'menu'; } // Dropdown list attributes (name) if (!empty($aDropdownOptions['name'])) { $aDropdownOptions['list_attributes']['aria-labelledby'] = $aDropdownOptions['name']; } // Dropdown list attributes (items) $sItems = ''; foreach ($aDropdownOptions['items'] as $sKey => $aItemOptions) { if (!is_array($aItemOptions)) { if (!is_scalar($aItemOptions)) { throw new \LogicException('item option expects an array or a scalar value, "' . gettype($aItemOptions) . '" given'); } $aItemOptions = $aItemOptions === self::TYPE_ITEM_DIVIDER // Divider ? array('type' => self::TYPE_ITEM_DIVIDER) // Link : array( 'label' => $aItemOptions, 'type' => self::TYPE_ITEM_LINK, 'item_attributes' => array('href' => is_string($sKey) ? $sKey : null) ); } else { if (!isset($aItemOptions['label'])) { $aItemOptions['label'] = is_string($sKey) ? $sKey : null; } if (!isset($aItemOptions['type'])) { $aItemOptions['type'] = self::TYPE_ITEM_LINK; } } $sItems .= $this->renderItem($aItemOptions) . "\n"; } return sprintf( static::$dropdownListFormat, $this->createAttributesString($aDropdownOptions['list_attributes']), // List attributes $sItems // Items ); }
php
{ "resource": "" }
q248850
RequestHandler.process
validation
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $requestHandler = $request->getAttribute($this->handlerAttribute); if (empty($requestHandler)) { if ($this->continueOnEmpty) { return $handler->handle($request); } throw new RuntimeException('Empty request handler'); } if (is_string($requestHandler)) { $requestHandler = $this->container->get($requestHandler); } if (is_array($requestHandler) && count($requestHandler) === 2 && is_string($requestHandler[0])) { $requestHandler[0] = $this->container->get($requestHandler[0]); } if ($requestHandler instanceof MiddlewareInterface) { return $requestHandler->process($request, $handler); } if ($requestHandler instanceof RequestHandlerInterface) { return $requestHandler->handle($request); } if (is_callable($requestHandler)) { return (new CallableHandler($requestHandler))->process($request, $handler); } throw new RuntimeException(sprintf('Invalid request handler: %s', gettype($requestHandler))); }
php
{ "resource": "" }
q248851
SignupForm.signup
validation
public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { return $user; } } return null; }
php
{ "resource": "" }
q248852
UserController.actionCreate
validation
public function actionCreate() { $model = new User; if ($model->load($_POST) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); } }
php
{ "resource": "" }
q248853
User.getIsSuperAdmin
validation
public function getIsSuperAdmin() { if ($this->_isSuperAdmin !== null) { return $this->_isSuperAdmin; } $this->_isSuperAdmin = in_array($this->username, Yii::$app->getModule('auth')->superAdmins); return $this->_isSuperAdmin; }
php
{ "resource": "" }
q248854
PasswordResetRequestForm.sendEmail
validation
public function sendEmail() { /* @var $user User */ $user = User::findOne([ 'status' => User::STATUS_ACTIVE, 'email' => $this->email, ]); if ($user) { $user->generatePasswordResetToken(); if ($user->save()) { return \Yii::$app->mailer->compose('@auth/views/mail/passwordResetToken', ['user' => $user]) ->setFrom([\Yii::$app->getModule('auth')->supportEmail => \Yii::$app->name]) ->setTo($this->email) ->setSubject(Yii::t('auth.reset-password', 'Password reset for {name}', ['name' => \Yii::$app->name])) ->send(); } } return false; }
php
{ "resource": "" }
q248855
ProfileController.actionUpdate
validation
public function actionUpdate() { $model = $this->findModel(); $model->setScenario('profile'); if ($model->load($_POST) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', [ 'model' => $model, ]); } }
php
{ "resource": "" }
q248856
RequestHandler.encodeBearer
validation
private function encodeBearer ($consumer_key, $consumer_secret){ // Create Bearer Token as per Twitter recomends at // https://dev.twitter.com/docs/auth/application-only-auth $consumer_key = rawurlencode($consumer_key); $consumer_secret = rawurlencode($consumer_secret); return base64_encode($consumer_key . ':' . $consumer_secret); }
php
{ "resource": "" }
q248857
RequestHandler.authenticateApp
validation
public function authenticateApp ($consumer_key, $consumer_secret) { $bearer_token = $this->encodeBearer($consumer_key, $consumer_secret); // Twitter Required Headers $headers = array( 'Authorization' => 'Basic ' . $bearer_token, 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8' ); // Twitter Required Body $body = 'grant_type=client_credentials'; $response = $this->client->post('/oauth2/token', $headers, $body)->send(); $data = $response->json(); $this->bearer = $data['access_token']; return $this->bearer; }
php
{ "resource": "" }
q248858
Client.api_request
validation
public function api_request ($path, $options) { $data = $this->requestHandler->request($path, $options); return json_encode($data->json); }
php
{ "resource": "" }
q248859
StorageRegistry.get
validation
public function get($name) { if ( ! isset($this->accounts[$name])) { throw new \RuntimeException("No account found with " . $name); } return $this->accounts[$name]; }
php
{ "resource": "" }
q248860
SharedAccessSignature.setPermissionSet
validation
public function setPermissionSet($value = array()) { foreach ($value as $url) { if (strpos($url, $this->accountName) === false) { throw new Exception('The permission set can only contain URLs for the account name specified in the Credentials_SharedAccessSignature instance.'); } } $this->permissionSet = $value; }
php
{ "resource": "" }
q248861
SharedAccessSignature.createSignedQueryString
validation
public function createSignedQueryString( $path = '/', $queryString = '', $resource = 'b', $permissions = 'r', $start = '', $expiry = '', $identifier = '' ) { // Parts $parts = array(); if ($start !== '') { $parts[] = 'st=' . urlencode($start); } $parts[] = 'se=' . urlencode($expiry); $parts[] = 'sr=' . $resource; $parts[] = 'sp=' . $permissions; if ($identifier !== '') { $parts[] = 'si=' . urlencode($identifier); } $parts[] = 'sig=' . urlencode($this->createSignature($path, $resource, $permissions, $start, $expiry, $identifier)); // Assemble parts and query string if ($queryString != '') { $queryString .= '&'; } $queryString .= implode('&', $parts); return $queryString; }
php
{ "resource": "" }
q248862
SharedAccessSignature.permissionMatchesRequest
validation
public function permissionMatchesRequest( $permissionUrl = '', $requestUrl = '', $resourceType = Storage::RESOURCE_UNKNOWN, $requiredPermission = CredentialsAbstract::PERMISSION_READ ) { // Build requirements $requiredResourceType = $resourceType; if ($requiredResourceType == Storage::RESOURCE_BLOB) { $requiredResourceType .= Storage::RESOURCE_CONTAINER; } // Parse permission url $parsedPermissionUrl = parse_url($permissionUrl); // Parse permission properties $permissionParts = explode('&', $parsedPermissionUrl['query']); // Parse request url $parsedRequestUrl = parse_url($requestUrl); // Check if permission matches request $matches = true; foreach ($permissionParts as $part) { list($property, $value) = explode('=', $part, 2); if ($property == 'sr') { $matches = $matches && (strpbrk($value, $requiredResourceType) !== false); } if ($property == 'sp') { $matches = $matches && (strpbrk($value, $requiredPermission) !== false); } } // Ok, but... does the resource match? $matches = $matches && (strpos($parsedRequestUrl['path'], $parsedPermissionUrl['path']) !== false); // Return return $matches; }
php
{ "resource": "" }
q248863
SharedAccessSignature.signRequestUrl
validation
public function signRequestUrl( $requestUrl = '', $resourceType = Storage::RESOURCE_UNKNOWN, $requiredPermission = CredentialsAbstract::PERMISSION_READ ) { // Look for a matching permission foreach ($this->getPermissionSet() as $permittedUrl) { if ($this->permissionMatchesRequest($permittedUrl, $requestUrl, $resourceType, $requiredPermission)) { // This matches, append signature data $parsedPermittedUrl = parse_url($permittedUrl); if (strpos($requestUrl, '?') === false) { $requestUrl .= '?'; } else { $requestUrl .= '&'; } $requestUrl .= $parsedPermittedUrl['query']; // Return url return $requestUrl; } } // Return url, will be unsigned... return $requestUrl; }
php
{ "resource": "" }
q248864
SharedAccessSignature.signRequestHeaders
validation
public function signRequestHeaders( $httpVerb = 'GET', $path = '/', $query = array(), $headers = null, $forTableStorage = false, $resourceType = Storage::RESOURCE_UNKNOWN, $requiredPermission = CredentialsAbstract::PERMISSION_READ, $rawData = null ) { return $headers; }
php
{ "resource": "" }
q248865
BlobClient.performRequest
validation
protected function performRequest( $path = '/', $query = array(), $httpVerb = 'GET', $headers = array(), $forTableStorage = false, $rawData = null, $resourceType = self::RESOURCE_UNKNOWN, $requiredPermission = self::PERMISSION_READ ) { // Clean path if (strpos($path, '/') !== 0) { $path = '/' . $path; } if (!isset($headers['Content-Type'])) { $headers['Content-Type'] = ''; } if (!isset($headers['content-length']) && ($rawData !== null || $httpVerb == "PUT")) { $headers['Content-Length'] = strlen((string)$rawData); } $headers['Expect'] = ''; // Add version header $headers['x-ms-version'] = $this->apiVersion; // Generate URL $path = str_replace(' ', '%20', $path); $requestUrl = $this->getBaseUrl() . $path; if (count($query) > 0) { $queryString = ''; foreach ($query as $key => $value) { $queryString .= ($queryString ? '&' : '?') . rawurlencode($key) . '=' . rawurlencode($value); } $requestUrl .= $queryString; } $requestUrl = $this->credentials->signRequestUrl($requestUrl, $resourceType, $requiredPermission); $headers = $this->credentials->signRequestHeaders( $httpVerb, $path, $query, $headers, $forTableStorage, $resourceType, $requiredPermission, $rawData ); return $this->httpClient->request($httpVerb, $requestUrl, $rawData, $headers); }
php
{ "resource": "" }
q248866
BlobClient.blobExists
validation
public function blobExists($containerName = '', $blobName = '', $snapshotId = null) { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); Assertion::notEmpty($blobName, 'Blob name is not specified.'); try { $this->getBlobInstance($containerName, $blobName, $snapshotId); } catch (BlobException $e) { return false; } return true; }
php
{ "resource": "" }
q248867
BlobClient.containerExists
validation
public function containerExists($containerName = '') { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); // List containers $containers = $this->listContainers($containerName, 1); foreach ($containers as $container) { if ($container->Name == $containerName) { return true; } } return false; }
php
{ "resource": "" }
q248868
BlobClient.createContainerIfNotExists
validation
public function createContainerIfNotExists($containerName = '', $metadata = array()) { if ( ! $this->containerExists($containerName)) { $this->createContainer($containerName, $metadata); } }
php
{ "resource": "" }
q248869
BlobClient.getContainerAcl
validation
public function getContainerAcl($containerName = '', $signedIdentifiers = false) { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); $response = $this->performRequest($containerName, array('restype' => 'container', 'comp' => 'acl'), 'GET', array(), false, null, self::RESOURCE_CONTAINER, self::PERMISSION_READ); if ( ! $response->isSuccessful()) { throw new BlobException($this->getErrorMessage($response, 'Resource could not be accessed.')); } if ($signedIdentifiers == false) { // Only private/blob/container $accessType = $response->getHeader(Storage::PREFIX_STORAGE_HEADER . 'blob-public-access'); if (strtolower($accessType) == 'true') { $accessType = self::ACL_PUBLIC_CONTAINER; } return $accessType; } $result = $this->parseResponse($response); if ( ! $result) { return array(); } $entries = null; if ($result->SignedIdentifier) { if (count($result->SignedIdentifier) > 1) { $entries = $result->SignedIdentifier; } else { $entries = array($result->SignedIdentifier); } } $returnValue = array(); foreach ($entries as $entry) { $returnValue[] = new SignedIdentifier( $entry->Id, $entry->AccessPolicy ? $entry->AccessPolicy->Start ? $entry->AccessPolicy->Start : '' : '', $entry->AccessPolicy ? $entry->AccessPolicy->Expiry ? $entry->AccessPolicy->Expiry : '' : '', $entry->AccessPolicy ? $entry->AccessPolicy->Permission ? $entry->AccessPolicy->Permission : '' : '' ); } return $returnValue; }
php
{ "resource": "" }
q248870
BlobClient.setContainerAcl
validation
public function setContainerAcl($containerName = '', $acl = self::ACL_PRIVATE, $signedIdentifiers = array()) { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); $headers = array(); // Acl specified? if ($acl != self::ACL_PRIVATE && !is_null($acl) && $acl != '') { $headers[Storage::PREFIX_STORAGE_HEADER . 'blob-public-access'] = $acl; } $policies = null; if (is_array($signedIdentifiers) && count($signedIdentifiers) > 0) { $policies = ''; $policies .= '<?xml version="1.0" encoding="utf-8"?>' . "\r\n"; $policies .= '<SignedIdentifiers>' . "\r\n"; foreach ($signedIdentifiers as $signedIdentifier) { $policies .= ' <SignedIdentifier>' . "\r\n"; $policies .= ' <Id>' . $signedIdentifier->Id . '</Id>' . "\r\n"; $policies .= ' <AccessPolicy>' . "\r\n"; if ($signedIdentifier->Start != '') $policies .= ' <Start>' . $signedIdentifier->Start . '</Start>' . "\r\n"; if ($signedIdentifier->Expiry != '') $policies .= ' <Expiry>' . $signedIdentifier->Expiry . '</Expiry>' . "\r\n"; if ($signedIdentifier->Permissions != '') $policies .= ' <Permission>' . $signedIdentifier->Permissions . '</Permission>' . "\r\n"; $policies .= ' </AccessPolicy>' . "\r\n"; $policies .= ' </SignedIdentifier>' . "\r\n"; } $policies .= '</SignedIdentifiers>' . "\r\n"; } $response = $this->performRequest($containerName, array('restype' => 'container', 'comp' => 'acl'), 'PUT', $headers, false, $policies, self::RESOURCE_CONTAINER, self::PERMISSION_WRITE); if ( ! $response->isSuccessful()) { throw new BlobException($this->getErrorMessage($response, 'Resource could not be accessed.')); } }
php
{ "resource": "" }
q248871
BlobClient.getContainerMetadata
validation
public function getContainerMetadata($containerName = '') { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); return $this->getContainer($containerName)->Metadata; }
php
{ "resource": "" }
q248872
BlobClient.setContainerMetadata
validation
public function setContainerMetadata($containerName = '', $metadata = array(), $additionalHeaders = array()) { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); Assertion::isArray($metadata, 'Meta data should be an array of key and value pairs.'); if (count($metadata) == 0) { return; } $headers = array(); $headers = array_merge($headers, $this->generateMetadataHeaders($metadata)); foreach ($additionalHeaders as $key => $value) { $headers[$key] = $value; } $response = $this->performRequest($containerName, array('restype' => 'container', 'comp' => 'metadata'), 'PUT', $headers, false, null, self::RESOURCE_CONTAINER, self::PERMISSION_WRITE); if ( ! $response->isSuccessful()) { throw new BlobException($this->getErrorMessage($response, 'Resource could not be accessed.')); } }
php
{ "resource": "" }
q248873
BlobClient.putBlobData
validation
public function putBlobData($containerName = '', $blobName = '', $data = '', $metadata = array(), $leaseId = null, $additionalHeaders = array()) { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); Assertion::notEmpty($blobName, 'Blob name is not specified.'); self::assertValidRootContainerBlobName($containerName, $blobName); $headers = array(); if (!is_null($leaseId)) { $headers['x-ms-lease-id'] = $leaseId; } $headers = array_merge($headers, $this->generateMetadataHeaders($metadata)); foreach ($additionalHeaders as $key => $value) { $headers[$key] = $value; } $headers[Storage::PREFIX_STORAGE_HEADER . 'blob-type'] = self::BLOBTYPE_BLOCK; $resourceName = self::createResourceName($containerName , $blobName); $response = $this->performRequest($resourceName, array(), 'PUT', $headers, false, $data, self::RESOURCE_BLOB, self::PERMISSION_WRITE); if ( ! $response->isSuccessful()) { throw new BlobException($this->getErrorMessage($response, 'Resource could not be accessed.')); } return new BlobInstance( $containerName, $blobName, null, $response->getHeader('Etag'), $response->getHeader('Last-modified'), $this->getBaseUrl() . '/' . $containerName . '/' . $blobName, strlen($data), '', '', '', false, $metadata ); }
php
{ "resource": "" }
q248874
BlobClient.putBlock
validation
public function putBlock($containerName = '', $blobName = '', $identifier = '', $contents = '', $leaseId = null) { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); Assertion::notEmpty($blobName, 'Blob name is not specified.'); Assertion::notEmpty($identifier, 'Block identifier is not specified.'); self::assertValidRootContainerBlobName($containerName, $blobName); if (strlen($contents) > self::MAX_BLOB_TRANSFER_SIZE) { throw new BlobException('Block size is too big.'); } $headers = array(); if (!is_null($leaseId)) { $headers['x-ms-lease-id'] = $leaseId; } $resourceName = self::createResourceName($containerName , $blobName); $response = $this->performRequest($resourceName, array('comp' => 'block', 'blockid' => base64_encode($identifier)), 'PUT', $headers, false, $contents, self::RESOURCE_BLOB, self::PERMISSION_WRITE); if ( ! $response->isSuccessful()) { throw new BlobException($this->getErrorMessage($response, 'Resource could not be accessed.')); } }
php
{ "resource": "" }
q248875
BlobClient.putBlockList
validation
public function putBlockList($containerName = '', $blobName = '', $blockList = array(), $metadata = array(), $leaseId = null, $additionalHeaders = array()) { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); Assertion::notEmpty($blobName, 'Blob name is not specified.'); Assertion::notEmpty($blockList, 'Block list does not contain any elements.'); self::assertValidRootContainerBlobName($containerName, $blobName); $blocks = ''; foreach ($blockList as $block) { $blocks .= ' <Latest>' . base64_encode($block) . '</Latest>' . "\n"; } $fileContents = utf8_encode(implode("\n", array( '<?xml version="1.0" encoding="utf-8"?>', '<BlockList>', $blocks, '</BlockList>' ))); $headers = array(); if (!is_null($leaseId)) { $headers['x-ms-lease-id'] = $leaseId; } $headers = array_merge($headers, $this->generateMetadataHeaders($metadata)); foreach ($additionalHeaders as $key => $value) { $headers[$key] = $value; } $resourceName = self::createResourceName($containerName , $blobName); $response = $this->performRequest($resourceName, array('comp' => 'blocklist'), 'PUT', $headers, false, $fileContents, self::RESOURCE_BLOB, self::PERMISSION_WRITE); if ( ! $response->isSuccessful()) { throw new BlobException($this->getErrorMessage($response, 'Resource could not be accessed.')); } }
php
{ "resource": "" }
q248876
BlobClient.getBlockList
validation
public function getBlockList($containerName = '', $blobName = '', $snapshotId = null, $leaseId = null, $type = 0) { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); Assertion::notEmpty($blobName, 'Blob name is not specified.'); if ($type < 0 || $type > 2) { throw new BlobException('Invalid type of block list to retrieve.'); } $blockListType = 'all'; if ($type == 1) { $blockListType = 'committed'; } if ($type == 2) { $blockListType = 'uncommitted'; } $headers = array(); if (!is_null($leaseId)) { $headers['x-ms-lease-id'] = $leaseId; } $query = array('comp' => 'blocklist', 'blocklisttype' => $blockListType); if (!is_null($snapshotId)) { $query['snapshot'] = $snapshotId; } $resourceName = self::createResourceName($containerName , $blobName); $response = $this->performRequest($resourceName, $query, 'GET', $headers, false, null, self::RESOURCE_BLOB, self::PERMISSION_READ); if ( ! $response->isSuccessful()) { throw new BlobException($this->getErrorMessage($response, 'Resource could not be accessed.')); } $blockList = $this->parseResponse($response); $returnValue = array(); if ($blockList->CommittedBlocks) { foreach ($blockList->CommittedBlocks->Block as $block) { $returnValue['CommittedBlocks'][] = (object)array( 'Name' => (string)$block->Name, 'Size' => (string)$block->Size ); } } if ($blockList->UncommittedBlocks) { foreach ($blockList->UncommittedBlocks->Block as $block) { $returnValue['UncommittedBlocks'][] = (object)array( 'Name' => (string)$block->Name, 'Size' => (string)$block->Size ); } } return $returnValue; }
php
{ "resource": "" }
q248877
BlobClient.getBlobInstance
validation
public function getBlobInstance($containerName = '', $blobName = '', $snapshotId = null, $leaseId = null, $additionalHeaders = array()) { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); Assertion::notEmpty($blobName, 'Blob name is not specified.'); self::assertValidRootContainerBlobName($containerName, $blobName); $query = array(); if (!is_null($snapshotId)) { $query['snapshot'] = $snapshotId; } $headers = array(); if (!is_null($leaseId)) { $headers['x-ms-lease-id'] = $leaseId; } foreach ($additionalHeaders as $key => $value) { $headers[$key] = $value; } $resourceName = self::createResourceName($containerName , $blobName); $response = $this->performRequest($resourceName, $query, 'HEAD', $headers, false, null, self::RESOURCE_BLOB, self::PERMISSION_READ); if ( ! $response->isSuccessful()) { throw new BlobException($this->getErrorMessage($response, 'Resource could not be accessed.')); } $metadata = $this->parseMetadataHeaders($response->getHeaders()); return new BlobInstance( $containerName, $blobName, $snapshotId, $response->getHeader('Etag'), $response->getHeader('Last-modified'), $this->getBaseUrl() . '/' . $containerName . '/' . $blobName, $response->getHeader('Content-Length'), $response->getHeader('Content-Type'), $response->getHeader('Content-Encoding'), $response->getHeader('Content-Language'), $response->getHeader('Cache-Control'), $response->getHeader('x-ms-blob-type'), $response->getHeader('x-ms-lease-status'), false, $metadata ); }
php
{ "resource": "" }
q248878
BlobClient.getBlobProperties
validation
public function getBlobProperties($containerName = '', $blobName = '', $snapshotId = null, $leaseId = null) { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); Assertion::notEmpty($blobName, 'Blob name is not specified.'); self::assertValidRootContainerBlobName($containerName, $blobName); return $this->getBlobInstance($containerName, $blobName, $snapshotId, $leaseId); }
php
{ "resource": "" }
q248879
BlobClient.generateSharedAccessUrl
validation
public function generateSharedAccessUrl($containerName = '', $blobName = '', $resource = 'b', $permissions = 'r', $start = '', $expiry = '', $identifier = '') { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); $resourceName = self::createResourceName($containerName , $blobName); return $this->getBaseUrl() . '/' . $resourceName . '?' . $this->sharedAccessSignatureCredentials->createSignedQueryString( $resourceName, '', $resource, $permissions, $start, $expiry, $identifier ); }
php
{ "resource": "" }
q248880
BlobClient.createResourceName
validation
public static function createResourceName($containerName = '', $blobName = '') { $resourceName = $containerName . '/' . $blobName; if ($containerName === '' || $containerName === '$root') { $resourceName = $blobName; } if ($blobName === '') { $resourceName = $containerName; } return $resourceName; }
php
{ "resource": "" }
q248881
BlobClient.isValidContainerName
validation
public static function isValidContainerName($containerName = '') { if ($containerName == '$root') { return true; } if (preg_match("/^[a-z0-9][a-z0-9-]*$/", $containerName) === 0) { return false; } if (strpos($containerName, '--') !== false) { return false; } if (strtolower($containerName) != $containerName) { return false; } if (strlen($containerName) < 3 || strlen($containerName) > 63) { return false; } if (substr($containerName, -1) == '-') { return false; } return true; }
php
{ "resource": "" }
q248882
BlobClient.getErrorMessage
validation
protected function getErrorMessage($response, $alternativeError = 'Unknown error.') { $xml = $this->parseResponse($response); if ($xml && $xml->Message) { return "[" . $response->getStatusCode() . "] " . (string)$xml->Message ."\n" . (string)$xml->AuthenticationErrorDetail; } else { return $alternativeError; } }
php
{ "resource": "" }
q248883
BlobClient.getBaseUrl
validation
public function getBaseUrl() { if ($this->credentials->usePathStyleUri()) { return $this->host . '/' . $this->accountName; } return $this->host; }
php
{ "resource": "" }
q248884
BlobClient.parseMetadataHeaders
validation
protected function parseMetadataHeaders($headers = array()) { // Validate if (!is_array($headers)) { return array(); } // Return metadata $metadata = array(); foreach ($headers as $key => $value) { if (substr(strtolower($key), 0, 10) == "x-ms-meta-") { $metadata[str_replace("x-ms-meta-", '', strtolower($key))] = $value; } } return $metadata; }
php
{ "resource": "" }
q248885
BlobClient.parseMetadataElement
validation
protected function parseMetadataElement($element = null) { // Metadata present? if (!is_null($element) && isset($element->Metadata) && !is_null($element->Metadata)) { return get_object_vars($element->Metadata); } return array(); }
php
{ "resource": "" }
q248886
Stream.getStorageClient
validation
protected function getStorageClient($path = '') { if (is_null($this->storageClient)) { $url = explode(':', $path); if (!$url) { throw new BlobException('Could not parse path "' . $path . '".'); } $this->storageClient = BlobClient::getWrapperClient($url[0]); if (!$this->storageClient) { throw new BlobException('No storage client registered for stream type "' . $url[0] . '://".'); } } return $this->storageClient; }
php
{ "resource": "" }
q248887
Stream.getFileName
validation
protected function getFileName($path) { $url = parse_url($path); if ($url['host']) { $fileName = isset($url['path']) ? $url['path'] : $url['host']; if (strpos($fileName, '/') === 0) { $fileName = substr($fileName, 1); } return $fileName; } return ''; }
php
{ "resource": "" }
q248888
Stream.stream_open
validation
public function stream_open($path, $mode, $options, &$opened_path) { $this->fileName = $path; $this->temporaryFileName = tempnam(sys_get_temp_dir(), 'azure'); // Check the file can be opened $fh = @fopen($this->temporaryFileName, $mode); if ($fh === false) { return false; } fclose($fh); // Write mode? if (strpbrk($mode, 'wax+')) { $this->writeMode = true; } else { $this->writeMode = false; } // If read/append, fetch the file if (!$this->writeMode || strpbrk($mode, 'ra+')) { $this->getStorageClient($this->fileName)->getBlob( $this->getContainerName($this->fileName), $this->getFileName($this->fileName), $this->temporaryFileName ); } // Open temporary file handle $this->temporaryFileHandle = fopen($this->temporaryFileName, $mode); // Ok! return true; }
php
{ "resource": "" }
q248889
Stream.stream_close
validation
public function stream_close() { @fclose($this->temporaryFileHandle); // Upload the file? if ($this->writeMode) { // Make sure the container exists $containerExists = $this->getStorageClient($this->fileName)->containerExists( $this->getContainerName($this->fileName) ); if (!$containerExists) { $this->getStorageClient($this->fileName)->createContainer( $this->getContainerName($this->fileName) ); } // Upload the file try { $this->getStorageClient($this->fileName)->putBlob( $this->getContainerName($this->fileName), $this->getFileName($this->fileName), $this->temporaryFileName ); } catch (BlobException $ex) { @unlink($this->temporaryFileName); unset($this->storageClient); throw $ex; } } @unlink($this->temporaryFileName); unset($this->storageClient); }
php
{ "resource": "" }
q248890
Stream.stream_flush
validation
public function stream_flush() { $result = fflush($this->temporaryFileHandle); // Upload the file? if ($this->writeMode) { // Make sure the container exists $containerExists = $this->getStorageClient($this->fileName)->containerExists( $this->getContainerName($this->fileName) ); if (!$containerExists) { $this->getStorageClient($this->fileName)->createContainer( $this->getContainerName($this->fileName) ); } // Upload the file try { $this->getStorageClient($this->fileName)->putBlob( $this->getContainerName($this->fileName), $this->getFileName($this->fileName), $this->temporaryFileName ); } catch (BlobException $ex) { @unlink($this->temporaryFileName); unset($this->storageClient); throw $ex; } } return $result; }
php
{ "resource": "" }
q248891
Stream.unlink
validation
public function unlink($path) { $this->getStorageClient($path)->deleteBlob( $this->getContainerName($path), $this->getFileName($path) ); // Clear the stat cache for this path. clearstatcache(true, $path); return true; }
php
{ "resource": "" }
q248892
Stream.rename
validation
public function rename($path_from, $path_to) { if ($this->getContainerName($path_from) != $this->getContainerName($path_to)) { throw new BlobException('Container name can not be changed.'); } if ($this->getFileName($path_from) == $this->getContainerName($path_to)) { return true; } $this->getStorageClient($path_from)->copyBlob( $this->getContainerName($path_from), $this->getFileName($path_from), $this->getContainerName($path_to), $this->getFileName($path_to) ); $this->getStorageClient($path_from)->deleteBlob( $this->getContainerName($path_from), $this->getFileName($path_from) ); // Clear the stat cache for the affected paths. clearstatcache(true, $path_from); clearstatcache(true, $path_to); return true; }
php
{ "resource": "" }
q248893
Stream.url_stat
validation
public function url_stat($path, $flags) { $stat = array(); $stat['dev'] = 0; $stat['ino'] = 0; $stat['mode'] = 0; $stat['nlink'] = 0; $stat['uid'] = 0; $stat['gid'] = 0; $stat['rdev'] = 0; $stat['size'] = 0; $stat['atime'] = 0; $stat['mtime'] = 0; $stat['ctime'] = 0; $stat['blksize'] = 0; $stat['blocks'] = 0; $info = null; try { $info = $this->getStorageClient($path)->getBlobInstance( $this->getContainerName($path), $this->getFileName($path) ); $stat['size'] = $info->Size; // Set the modification time and last modified to the Last-Modified header. $lastmodified = strtotime($info->LastModified); $stat['mtime'] = $lastmodified; $stat['ctime'] = $lastmodified; // Entry is a regular file. $stat['mode'] = 0100000; return array_values($stat) + $stat; } catch (BlobException $ex) { // Unexisting file... return false; } }
php
{ "resource": "" }
q248894
Stream.dir_opendir
validation
public function dir_opendir($path, $options) { $this->blobs = $this->getStorageClient($path)->listBlobs( $this->getContainerName($path) ); return is_array($this->blobs); }
php
{ "resource": "" }
q248895
Stream.dir_readdir
validation
public function dir_readdir() { $object = current($this->blobs); if ($object !== false) { next($this->blobs); return $object->Name; } return false; }
php
{ "resource": "" }
q248896
PHPMailer.AddAddress
validation
function AddAddress($address, $name = "") { $cur = count($this->to); $this->to[$cur][0] = trim($address); $this->to[$cur][1] = $name; }
php
{ "resource": "" }
q248897
PHPMailer.AddReplyTo
validation
function AddReplyTo($address, $name = "") { $cur = count($this->ReplyTo); $this->ReplyTo[$cur][0] = trim($address); $this->ReplyTo[$cur][1] = $name; }
php
{ "resource": "" }
q248898
PHPMailer.Send
validation
function Send() { $header = ""; $body = ""; $result = true; if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { $this->SetError($this->Lang("provide_address")); return false; } // Set whether the message is multipart/alternative if(!empty($this->AltBody)) $this->ContentType = "multipart/alternative"; $this->error_count = 0; // reset errors $this->SetMessageType(); $header .= $this->CreateHeader(); $body = $this->CreateBody(); if($body == "") { return false; } // Choose the mailer switch($this->Mailer) { case "sendmail": $result = $this->SendmailSend($header, $body); break; case "mail": $result = $this->MailSend($header, $body); break; case "smtp": $result = $this->SmtpSend($header, $body); break; default: $this->SetError($this->Mailer . $this->Lang("mailer_not_supported")); $result = false; break; } return $result; }
php
{ "resource": "" }
q248899
PHPMailer.SmtpClose
validation
function SmtpClose() { if($this->smtp != NULL) { if($this->smtp->Connected()) { $this->smtp->Quit(); $this->smtp->Close(); } } }
php
{ "resource": "" }