_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q6700
AttributeTypeAvMeta.getAttributeAv
train
public function getAttributeAv(ConnectionInterface $con = null) { if ($this->aAttributeAv === null && ($this->attribute_av_id !== null)) { $this->aAttributeAv = AttributeAvQuery::create()->findPk($this->attribute_av_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aAttributeAv->addAttributeTypeAvMetas($this); */ } return $this->aAttributeAv; }
php
{ "resource": "" }
q6701
AttributeTypeAvMeta.setAttributeAttributeType
train
public function setAttributeAttributeType(ChildAttributeAttributeType $v = null) { if ($v === null) { $this->setAttributeAttributeTypeId(NULL); } else { $this->setAttributeAttributeTypeId($v->getId()); } $this->aAttributeAttributeType = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildAttributeAttributeType object, it will not be re-added. if ($v !== null) { $v->addAttributeTypeAvMeta($this); } return $this; }
php
{ "resource": "" }
q6702
AttributeTypeAvMeta.getAttributeAttributeType
train
public function getAttributeAttributeType(ConnectionInterface $con = null) { if ($this->aAttributeAttributeType === null && ($this->attribute_attribute_type_id !== null)) { $this->aAttributeAttributeType = ChildAttributeAttributeTypeQuery::create()->findPk($this->attribute_attribute_type_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aAttributeAttributeType->addAttributeTypeAvMetas($this); */ } return $this->aAttributeAttributeType; }
php
{ "resource": "" }
q6703
Owns.scopeOwns
train
public function scopeOwns(Builder $query, Model $related, ?string $foreignKey = null): Builder { if (\is_null($foreignKey)) { $foreignKey = $this->getForeignKey(); } return $query->where( $this->getKeyName(), $related->getAttribute($foreignKey) ); }
php
{ "resource": "" }
q6704
Collection.setAt
train
public function setAt($offset, $data, $options = []) { $keys = is_array($offset) ? $offset : ($offset !== null ? explode('.', $offset) : []); $name = array_shift($keys); if ($keys) { $this->get($name)->setAt($keys, $data, $options); } if ($schema = $this->schema()) { $data = $schema->cast(null, $data, [ 'exists' => isset($options['exists']) ? $options['exists'] : null, 'parent' => $this, 'basePath' => $this->basePath(), 'defaults' => true ]); } if ($name !== null) { if (!is_numeric($name)) { throw new ORMException("Invalid index `" . $name . "` for a collection, must be a numeric value."); } $previous = isset($this->_data[$name]) ? $this->_data[$name] : null; $this->_data[$name] = $data; if ($previous instanceof HasParentsInterface) { $previous->unsetParent($this); } } else { $this->_data[] = $data; $name = key($this->_data); } if ($data instanceof HasParentsInterface) { $data->setParent($this, $name); } $this->_modified = true; return $this; }
php
{ "resource": "" }
q6705
Collection.offsetExists
train
public function offsetExists($offset) { $keys = is_array($offset) ? $offset : explode('.', $offset); if (!$keys) { return false; } $name = array_shift($keys); if ($keys) { if (!array_key_exists($name, $this->_data)) { return false; } $value = $this->_data[$name]; if ($value instanceof ArrayAccess) { return $value->offsetExists($keys); } return false; } return array_key_exists($name, $this->_data); }
php
{ "resource": "" }
q6706
Collection.modified
train
public function modified($options = []) { $options += ['embed' => false]; if ($this->_modified) { return true; } foreach ($this->_data as $index => $entity) { if (is_object($entity) && method_exists($entity, 'modified') && $entity->modified($options)) { return true; } } return false; }
php
{ "resource": "" }
q6707
Collection.errors
train
public function errors($options = []) { $errors = []; $errored = false; foreach ($this as $entity) { $result = $entity->errors($options); $errors[] = $result; if ($result) { $errored = true; } } return $errored ? $errors : []; }
php
{ "resource": "" }
q6708
Collection.hierarchy
train
public function hierarchy($prefix = '', &$ignore = [], $index = false) { $hash = spl_object_hash($this); if (isset($ignore[$hash])) { return false; } $ignore[$hash] = true; $result = []; foreach ($this as $entity) { if ($hierarchy = $entity->hierarchy($prefix, $ignore, true)) { $result += $hierarchy; } } return $index ? $result : array_keys($result); }
php
{ "resource": "" }
q6709
Handler.setDefaultOptions
train
protected function setDefaultOptions(OptionsResolver $resolver) { $resolver ->setDefaults(array( 'host' => function(Options $options) { if (isset($options['test']) && $options['test']) { return 'https://test-api.pin.net.au'; } return 'https://api.pin.net.au'; } )) ->setRequired(array( 'key' )) ->setDefined(array( 'host', 'test', 'timeout', )) ->setAllowedTypes('host', 'string') ->setAllowedTypes('key', 'string') ->setAllowedTypes('test', 'bool') ->setAllowedTypes('timeout', 'int') ; }
php
{ "resource": "" }
q6710
DocBlock.addAnnotation
train
public function addAnnotation($key, $value) { if (!isset($this->annotations[$key])) { $this->annotations[$key] = array(); } $this->annotations[$key][] = $value; }
php
{ "resource": "" }
q6711
UploadableListener.postLoad
train
public function postLoad(LifecycleEventArgs $eventArgs) { $entityManager = $eventArgs->getEntityManager(); $object = $eventArgs->getEntity(); $uploadableMeta = $this->getObjectExtendedMetadata($entityManager, $object); if ($uploadableMeta->hasUploadableProperties()) { $this->loadFiles($entityManager, $object, $uploadableMeta); } }
php
{ "resource": "" }
q6712
UploadableListener.preFlush
train
public function preFlush(PreFlushEventArgs $eventArgs) { $entityManager = $eventArgs->getEntityManager(); $unitOfWork = $entityManager->getUnitOfWork(); foreach ($unitOfWork->getIdentityMap() as $entities) { foreach ($entities as $object) { $uploadableMeta = $this->getObjectExtendedMetadata($entityManager, $object); if (!$uploadableMeta->hasUploadableProperties()) { continue; } $this->updateFiles($entityManager, $object, $uploadableMeta); } } }
php
{ "resource": "" }
q6713
UploadableListener.loadFiles
train
protected function loadFiles( EntityManagerInterface $entityManager, $object, UploadableClassMetadata $uploadableMeta ): void { $this->assertIsObject($object); $propertyManipulator = $this->getPropertyManipulator($entityManager); foreach ($uploadableMeta->getUploadableProperties() as $property => $config) { $key = $propertyManipulator->getPropertyValue($object, $property); if (!empty($key)) { $propertyManipulator->setAndSaveValue( $object, $config['targetField'], new File($key, $this->computeFilesystem($config)) ); } } }
php
{ "resource": "" }
q6714
UploadableListener.getPropertyManipulator
train
private function getPropertyManipulator(EntityManagerInterface $entityManager): PropertyManipulator { $oid = spl_object_hash($entityManager); if (!isset($this->propertyManipulators[$oid])) { $this->propertyManipulators[$oid] = new PropertyManipulator(); } return $this->propertyManipulators[$oid]; }
php
{ "resource": "" }
q6715
AttributeTypeI18nTableMap.doDelete
train
public static function doDelete($values, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(AttributeTypeI18nTableMap::DATABASE_NAME); } if ($values instanceof Criteria) { // rename for clarity $criteria = $values; } elseif ($values instanceof \AttributeType\Model\AttributeTypeI18n) { // it's a model object // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it's a primary key, or an array of pks $criteria = new Criteria(AttributeTypeI18nTableMap::DATABASE_NAME); // primary key is composite; we therefore, expect // the primary key passed to be an array of pkey values if (count($values) == count($values, COUNT_RECURSIVE)) { // array is not multi-dimensional $values = array($values); } foreach ($values as $value) { $criterion = $criteria->getNewCriterion(AttributeTypeI18nTableMap::ID, $value[0]); $criterion->addAnd($criteria->getNewCriterion(AttributeTypeI18nTableMap::LOCALE, $value[1])); $criteria->addOr($criterion); } } $query = AttributeTypeI18nQuery::create()->mergeWith($criteria); if ($values instanceof Criteria) { AttributeTypeI18nTableMap::clearInstancePool(); } elseif (!is_object($values)) { // it's a primary key, or an array of pks foreach ((array) $values as $singleval) { AttributeTypeI18nTableMap::removeInstanceFromPool($singleval); } } return $query->delete($con); }
php
{ "resource": "" }
q6716
AttributeTypeI18nTableMap.doInsert
train
public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(AttributeTypeI18nTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from AttributeTypeI18n object } // Set the correct dbName $query = AttributeTypeI18nQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = $query->doInsert($con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } return $pk; }
php
{ "resource": "" }
q6717
OciPdoAdapter.closeConnection
train
public function closeConnection() { if (is_resource($this->_dbh)) { $res = @oci_close($this->_dbh); $this->checkError($res); } else { $res = true; } return $res; }
php
{ "resource": "" }
q6718
OciPdoAdapter.getError
train
protected function getError() { if ($this->_error === false) { if (is_resource($this->_dbh)) { $this->_error = @oci_error($this->_dbh); } else { $this->_error = @oci_error(); } } return $this->_error; }
php
{ "resource": "" }
q6719
OciPdoAdapter.raiseError
train
public function raiseError() { $error = $this->getError(); if ($error === false) { return; } $this->_error = false; if ($error['offset'] == 0) { $message = sprintf('%s', $error['message']); } else { $message = sprintf('%s in %s at %s', $error['message'], $error['sqltext'], $error['offset']); } switch($this->getAttribute(PDO::ATTR_ERRMODE)) { case PDO::ERRMODE_SILENT: $message = sprintf('(%s) Error ' . $message, date('Y-m-d H:i:s')); error_log($message); break; case PDO::ERRMODE_WARNING: $message = 'Error ' . $message; $message = htmlentities($message, ENT_QUOTES); trigger_error($message, E_USER_ERROR); break; case PDO::ERRMODE_EXCEPTION: default: throw new Exception($message, $error['code']); } }
php
{ "resource": "" }
q6720
Buffer.first
train
public function first($options = []) { $result = $this->get($options); return is_object($result) ? $result->rewind() : reset($result); }
php
{ "resource": "" }
q6721
TranslatableListener.postLoad
train
public function postLoad(LifecycleEventArgs $eventArgs) { $this->loadTranslation( $eventArgs->getEntityManager(), $eventArgs->getEntity(), $this->getLocale() ); }
php
{ "resource": "" }
q6722
TranslatableListener.preFlush
train
public function preFlush(PreFlushEventArgs $eventArgs) { $entityManager = $eventArgs->getEntityManager(); $unitOfWork = $entityManager->getUnitOfWork(); foreach ($unitOfWork->getScheduledEntityInsertions() as $object) { $this->updateObjectTranslations($entityManager, $object); } foreach ($unitOfWork->getIdentityMap() as $entities) { foreach ($entities as $object) { $this->updateObjectTranslations($entityManager, $object); } } }
php
{ "resource": "" }
q6723
TranslatableListener.updateObjectTranslations
train
private function updateObjectTranslations(EntityManagerInterface $entityManager, $object): void { $translatableMeta = $this->getTranslatableMetadata($entityManager, $object); if (!$translatableMeta->hasTranslatableProperties()) { return; } foreach ($translatableMeta->getTranslationAssociationMetadatas() as $associationMeta) { $context = $this->getTranslationContext($entityManager, $associationMeta, $object); $locale = $this->translationHelper->getObjectLocale($context, $object); if (is_null($locale) || $locale === '') { $locale = $this->getLocale(); } $hasTranslatedProperties = $this->translationHelper->hasTranslatedProperties($context, $object); if (!isset($locale) && $hasTranslatedProperties) { throw new Exception\RuntimeException( "Neither object's locale nor the current locale was set for translatable properties" ); } if ($hasTranslatedProperties) { $this->translationHelper->copyPropertiesToTranslation( $context, $object, $locale ); } else { $this->translationHelper->removeEmptyTranslation($context, $object); } } }
php
{ "resource": "" }
q6724
Data.get
train
public function get($key, $default = null, $filter = null) { $result = $default; if ($this->has($key)) { $result = $this->offsetGet($key); } return $this->filter($result, $filter); }
php
{ "resource": "" }
q6725
Data.filter
train
protected function filter($value, $filter) { if (null !== $filter) { $value = Filter::_($value, $filter); } return $value; }
php
{ "resource": "" }
q6726
Data.is
train
public function is($key, $compareWith = true, $strictMode = false) { if (strpos($key, '.') === false) { $value = $this->get($key); } else { $value = $this->find($key); } if ($strictMode) { return $value === $compareWith; } /** @noinspection TypeUnsafeComparisonInspection */ return $value == $compareWith; }
php
{ "resource": "" }
q6727
Renderer.renderAxis
train
protected function renderAxis(AxisInterface $axis) { $options = array( 'opposite' => $axis->isOpposite(), 'showFirstLabel' => $axis->getLabel()->isShowFirst(), 'showLastLabel' => $axis->getLabel()->isShowLast(), ); if (0 < count($axis->getCategories())) { $options['categories'] = array_values($axis->getCategories()); } if (null !== $axis->getMaxValue()) { $options['max'] = $axis->getMaxValue(); } if (null !== $axis->getMinValue()) { $options['min'] = $axis->getMinValue(); } if (false === $axis->getTitle()->isEnabled()) { $options['title']['text'] = null; } else { if (null !== $axis->getTitle()->getText()) { $options['title']['text'] = $axis->getTitle()->getText(); } if (0 < count($axis->getTitle()->getStyles())) { $options['title']['style'] = $axis->getTitle()->getStyles(); } } $options['labels'] = array( 'enabled' => $axis->getLabel()->isEnabled(), ); if (null !== $axis->getLabel()->getAlign()) { $options['labels']['align'] = $axis->getLabel()->getAlign(); } if (0 < count($axis->getLabel()->getStyles())) { $options['labels']['style'] = $axis->getLabel()->getStyles(); } if (null !== $axis->getLabel()->getXOffset()) { $options['labels']['x'] = $axis->getLabel()->getXOffset(); } if (null !== $axis->getLabel()->getYOffset()) { $options['labels']['y'] = $axis->getLabel()->getYOffset(); } if (null !== $axis->getLabel()->getFormatter()) { $options['labels']['formatter'] = $axis->getLabel()->getFormatter(); } $options['tickWidth'] = $axis->getTickWidth(); $options['gridLineWidth'] = $axis->getGridLineWidth(); return $options; }
php
{ "resource": "" }
q6728
Renderer.renderDataPoint
train
protected function renderDataPoint(DataPointInterface $dataPoint) { $options = array(); if (null !== $dataPoint->getName()) { $options['name'] = $dataPoint->getName(); } if ($dataPoint instanceof PieDataPointInterface) { $options['sliced'] = $dataPoint->isSliced(); } if (null !== $dataPoint->getXValue()) { $options['x'] = $dataPoint->getXValue(); } $options['y'] = $dataPoint->getYValue(); return $options; }
php
{ "resource": "" }
q6729
ReturnTypeDeclarationSniff.getClosingParenthesis
train
private function getClosingParenthesis(File $phpcs_file, array $tokens, $stack_ptr): int { $closing_parenthesis = $tokens[$stack_ptr]['parenthesis_closer']; // In case the function is a closure, the closing parenthesis // may be positioned after a use language construct. if ($tokens[$stack_ptr]['code'] === T_CLOSURE) { $use = $phpcs_file->findNext(T_USE, $closing_parenthesis + 1, $tokens[$stack_ptr]['scope_opener']); if ($use !== false) { $open_bracket = $phpcs_file->findNext(T_OPEN_PARENTHESIS, $use + 1); $closing_parenthesis = $tokens[$open_bracket]['parenthesis_closer']; } } return $closing_parenthesis; }
php
{ "resource": "" }
q6730
ReturnTypeDeclarationSniff.fixSpacing
train
private function fixSpacing(File $phpcs_file, $tokens, $required_spacing, $start, $end): void { if (($start + 1) === $end && empty($required_spacing) === false) { //insert whitespace if there is no whitespace, and whitespace is required $phpcs_file->fixer->addContent($start, $required_spacing); return; } //otherwise, if there is whitespace, change the whitespace to the required spacing for ($i = ($start + 1); $i < $end; $i++) { if ($tokens[$i]['code'] !== T_WHITESPACE) { continue; } if (($i + 1) === $end) { $phpcs_file->fixer->replaceToken($i, $required_spacing); continue; } $phpcs_file->fixer->replaceToken($i, ''); } }
php
{ "resource": "" }
q6731
UserProfile.updateProfile
train
public function updateProfile() { if ($this->v["uID"] > 0) { // $GLOBALS["SL"]->user() returns an instance of the authenticated user... if ($this->v["uID"] == $GLOBALS["SL"]->REQ->uID || $this->v["user"]->hasRole('administrator')) { $user = User::find($GLOBALS["SL"]->REQ->uID); $user->name = $GLOBALS["SL"]->REQ->name; $user->email = $GLOBALS["SL"]->REQ->email; $user->save(); $user->loadRoles(); if ($this->v["user"]->hasRole('administrator')) { if ($GLOBALS["SL"]->REQ->has('roles') && is_array($GLOBALS["SL"]->REQ->roles) && sizeof($GLOBALS["SL"]->REQ->roles) > 0) { foreach ($user->roles as $i => $role) { if (in_array($role->DefID, $GLOBALS["SL"]->REQ->roles)) { if (!$user->hasRole($role->DefSubset)) { $user->assignRole($role->DefSubset); } } elseif ($user->hasRole($role->DefSubset)) { $user->revokeRole($role->DefSubset); } } } else { // no roles selected, delete all that exist foreach ($user->roles as $i => $role) { if ($user->hasRole($role->DefSubset)) { $user->revokeRole($role->DefSubset); } } } } $this->redir('/profile/' . urlencode($user->name), true); return true; } } return false; }
php
{ "resource": "" }
q6732
OciPdoLobStreamWrapper.getContext
train
public static function getContext(&$lob) { if (!self::$_isRegistered) { stream_wrapper_register(self::WRAPPER_NAME, get_class()); self::$_isRegistered = true; } return stream_context_create(array(self::WRAPPER_NAME => array('lob' => &$lob))); }
php
{ "resource": "" }
q6733
OciPdoLobStreamWrapper.stream_open
train
public function stream_open($path, $mode, $options, &$opened_path) { if (!preg_match('/^r[bt]?$/', $mode) || is_null($this->context)) { return false; } $opt = stream_context_get_options($this->context); if (!is_array($opt[self::WRAPPER_NAME]) || !isset($opt[self::WRAPPER_NAME]['lob'])) { return false; } if (!is_object($opt[self::WRAPPER_NAME]['lob']) && get_class($opt[self::WRAPPER_NAME]['lob']) != 'OCI-Lob') { return false; } $this->_lob = &$opt[self::WRAPPER_NAME]['lob']; $this->_lob->rewind(); return true; }
php
{ "resource": "" }
q6734
TreeSurvAPI.checkViewDataPerms
train
public function checkViewDataPerms($fld) { if ($fld && isset($fld->FldOpts) && intVal($fld->FldOpts) > 0) { if ($fld->FldOpts%7 > 0 && $fld->FldOpts%11 > 0 && $fld->FldOpts%13 > 0) { return true; } if (in_array($GLOBALS["SL"]->x["pageView"], ['full', 'full-pdf', 'full-xml'])) { return true; } if ($fld->FldOpts%13 == 0 || $fld->FldOpts%11 == 0) { return false; } return true; } return false; }
php
{ "resource": "" }
q6735
CommitCommand.execute
train
protected function execute(InputInterface $input, OutputInterface $output) { // Welcome $output->writeln( '<info>Welcome to the Cypress GitElephantBundle commit command.</info>' ); if ($input->getOption('no-push')) { $output->writeln( '<comment>--no-push option enabled (this option disable push commit to remotes)</comment>' ); } /** @var GitElephantRepositoryCollection $rc */ $rc = $this->getContainer()->get('git_repositories'); if ($rc->count() == 0) { throw new \Exception('Must have at least one Git repository. See https://github.com/matteosister/GitElephantBundle#how-to-use'); } /** @var Repository $repository */ foreach ($rc as $key => $repository) { if ($key == 0 || $key > 0 && $input->getOption('all')) { $repository->commit($input->getArgument('message'), !$input->getOption('no-stage-all')); if (!$input->getOption('no-push')) { /** @var Remote $remote */ foreach ($repository->getRemotes() as $remote) { $repository->push($remote->getName(), $repository->getMainBranch()->getName()); // Push last current branch commit to all remotes } } $output->writeln('New commit to local repository created ' . $repository->getName() . (!$input->getOption('no-push') ? ' and pushed to all remotes.' : '')); } } }
php
{ "resource": "" }
q6736
Schema.lock
train
public function lock($locked = true) { $this->_locked = $locked === false ? false : true; return $this; }
php
{ "resource": "" }
q6737
Schema.fields
train
public function fields($basePath = '') { $fields = []; foreach ($this->names() as $name) { $fields[$name] = null; } $names = Set::expand($fields); if ($basePath) { $parts = explode('.', $basePath); foreach ($parts as $part) { if (!isset($names[$part])) { return []; } $names = $names[$part]; } } return array_keys($names); }
php
{ "resource": "" }
q6738
Schema.defaults
train
public function defaults($basePath = null) { $defaults = []; foreach ($this->_columns as $key => $value) { if ($basePath) { $fieldName = strpos($key, $basePath . '.') === 0 ? substr($key, strlen($basePath) + 1) : null; } else { $fieldName = $key; } if (!$fieldName || $fieldName === '*' || strpos($fieldName, '.') !== false) { continue; } if (isset($value['default'])) { $defaults[$fieldName] = $value['default']; } } return $defaults; }
php
{ "resource": "" }
q6739
Schema.type
train
public function type($name) { if (!$this->has($name)) { return; } $column = $this->column($name); return isset($column['type']) ? $column['type'] : null; }
php
{ "resource": "" }
q6740
Schema.column
train
public function column($name, $params = []) { if (func_num_args() === 1) { if (!isset($this->_columns[$name])) { throw new ORMException("Unexisting column `'{$name}'`"); } return $this->_columns[$name]; } $column = $this->_initColumn($params); if ($column['type'] !== 'object' && !$column['array']) { $this->_columns[$name] = $column; return $this; } $relationship = $this->_classes['relationship']; $this->bind($name, [ 'type' => $column['array'] ? 'set' : 'entity', 'relation' => $column['array'] ? 'hasMany' : 'hasOne', 'to' => isset($column['class']) ? $column['class'] : Document::class, 'link' => $relationship::LINK_EMBEDDED, 'config' => isset($column['config']) ? $column['config'] : [] ]); $this->_columns[$name] = $column; return $this; }
php
{ "resource": "" }
q6741
Schema._initColumn
train
protected function _initColumn($column) { $defaults = [ 'type' => 'string', 'array' => false ]; if (is_string($column)) { $column = ['type' => $column]; } elseif (isset($column[0])) { $column['type'] = $column[0]; unset($column[0]); } $column += $defaults; return $column + ['null' => false]; }
php
{ "resource": "" }
q6742
Schema.append
train
public function append($fields) { if (is_array($fields)) { foreach ($fields as $key => $value) { $this->column($key, $value); } } else { foreach ($fields->fields() as $name) { $this->column($name, $fields->column($name)); } } return $this; }
php
{ "resource": "" }
q6743
Schema.virtuals
train
public function virtuals($attribute = null) { $fields = []; foreach ($this->_columns as $name => $field) { if (empty($field['virtual'])) { continue; } $fields[] = $name; } return $fields; }
php
{ "resource": "" }
q6744
Schema.belongsTo
train
public function belongsTo($name, $to, $config = []) { $defaults = [ 'to' => $to, 'relation' => 'belongsTo' ]; $config += $defaults; return $this->bind($name, $config); }
php
{ "resource": "" }
q6745
Schema.hasMany
train
public function hasMany($name, $to, $config = []) { $defaults = [ 'to' => $to, 'relation' => 'hasMany' ]; $config += $defaults; return $this->bind($name, $config); }
php
{ "resource": "" }
q6746
Schema.hasOne
train
public function hasOne($name, $to, $config = []) { $defaults = [ 'to' => $to, 'relation' => 'hasOne' ]; $config += $defaults; return $this->bind($name, $config); }
php
{ "resource": "" }
q6747
Schema.hasManyThrough
train
public function hasManyThrough($name, $through, $using, $config = []) { $defaults = [ 'through' => $through, 'using' => $using, 'relation' => 'hasManyThrough' ]; $config += $defaults; return $this->bind($name, $config); }
php
{ "resource": "" }
q6748
Schema.unbind
train
public function unbind($name) { if (!isset($this->_relations[$name])) { return; } unset($this->_relations[$name]); unset($this->_relationships[$name]); }
php
{ "resource": "" }
q6749
Schema.relation
train
public function relation($name) { if (isset($this->_relationships[$name])) { return $this->_relationships[$name]; } if (!isset($this->_relations[$name])) { throw new ORMException("Relationship `{$name}` not found."); } $config = $this->_relations[$name]; $relationship = $config['relation']; unset($config['relation']); $relation = $this->_classes[$relationship]; return $this->_relationships[$name] = new $relation($config + [ 'name' => $name, 'conventions' => $this->_conventions ]); }
php
{ "resource": "" }
q6750
Schema.relations
train
public function relations($embedded = false) { $result = []; foreach ($this->_relations as $field => $config) { if (!$config['embedded'] || $embedded) { $result[] = $field; } } return $result; }
php
{ "resource": "" }
q6751
Schema.hasRelation
train
public function hasRelation($name, $embedded = null) { if (!isset($this->_relations[$name])) { return false; } $relation = $this->_relations[$name]; if ($embedded === null) { return true; } return $embedded === $relation['embedded']; }
php
{ "resource": "" }
q6752
Schema.embed
train
public function embed(&$collection, $relations, $options = []) { $expanded = []; $relations = $this->expand($relations); $tree = $this->treeify($relations); $habtm = []; foreach ($tree as $name => $subtree) { $rel = $this->relation($name); if ($rel->type() === 'hasManyThrough') { $habtm[] = $name; continue; } $to = $rel->to(); $query = empty($relations[$name]) ? [] : $relations[$name]; if (is_callable($query)) { $options['query']['handler'] = $query; } else { $options['query'] = $query; } $related = $rel->embed($collection, $options); $subrelations = []; foreach ($relations as $path => $value) { if (preg_match('~^'.$name.'\.(.*)$~', $path, $matches)) { $subrelations[$matches[1]] = $value; } } if ($subrelations) { $to::definition()->embed($related, $subrelations, $options); } } foreach ($habtm as $name) { $rel = $this->relation($name); $related = $rel->embed($collection, $options); } }
php
{ "resource": "" }
q6753
Schema.expand
train
public function expand($relations) { if (is_string($relations)) { $relations = [$relations]; } $relations = Set::normalize($relations); foreach ($relations as $path => $value) { $num = strpos($path, '.'); $name = $num !== false ? substr($path, 0, $num) : $path; $rel = $this->relation($name); if ($rel->type() !== 'hasManyThrough') { continue; } $relPath = $rel->through() . '.' . $rel->using() . ($num !== false ? '.' . substr($path, $num + 1) : ''); if (!isset($relations[$relPath])) { $relations[$relPath] = $relations[$path]; } } return $relations; }
php
{ "resource": "" }
q6754
Schema.treeify
train
public function treeify($embed) { if (!$embed) { return []; } $embed = Set::expand(Set::normalize((array) $embed), ['affix' => 'embed']); $result = []; foreach ($embed as $relName => $value) { if (!isset($this->_relations[$relName])) { continue; } if ($this->_relations[$relName]['relation'] === 'hasManyThrough') { $rel = $this->relation($relName); if (!isset($result[$rel->through()]['embed'][$rel->using()])) { $result[$rel->through()]['embed'][$rel->using()] = $value; } } $result[$relName] = $value; } return $result; }
php
{ "resource": "" }
q6755
Schema.cast
train
public function cast($field = null, $data = [], $options = []) { $defaults = [ 'parent' => null, 'basePath' => null, 'exists' => null, 'defaults' => true ]; $options += $defaults; $options['class'] = $this->reference(); if ($field !== null) { $name = $options['basePath'] ? $options['basePath'] . '.' . $field : (string) $field; } else { $name = $options['basePath']; } if ($name === null) { return $this->_cast($name, $data, $options); } foreach([$name, preg_replace('~[^.]*$~', '*', $name, 1)] as $entry) { if (isset($this->_relations[$entry])) { return $this->_relationCast($field, $entry, $data, $options); } if (isset($this->_columns[$entry])) { return $this->_columnCast($field, $entry, $data, $options); } } if ($this->locked()) { return $data; } if (is_array($data)) { $options['class'] = Document::class; $options['basePath'] = $name; if (isset($data[0])) { return $this->_castArray($name, $data, $options); } else { return $this->_cast($name, $data, $options); } } return $data; }
php
{ "resource": "" }
q6756
Schema._relationCast
train
protected function _relationCast($field, $name, $data, $options) { $options = $this->_relations[$name] + $options; $options['basePath'] = $options['embedded'] ? $name : null; $options['schema'] = $options['embedded'] ? $this : null; if ($options['relation'] !== 'hasManyThrough') { $options['class'] = $options['to']; } else { $through = $this->relation($name); $options['class'] = $through->to(); } if ($field) { return $options['array'] ? $this->_castArray($name, $data, $options) : $this->_cast($name, $data, $options); } if (!isset($this->_columns[$name])) { return $data; } $column = $this->_columns[$name]; return $this->convert('cast', $column['type'], $data, $column, $options); }
php
{ "resource": "" }
q6757
Schema._columnCast
train
protected function _columnCast($field, $name, $data, $options) { $column = $this->_columns[$name]; if (!empty($column['setter'])) { $data = $column['setter']($options['parent'], $data, $name); } if ($column['array'] && $field) { return $this->_castArray($name, $data, $options); } return $this->convert('cast', $column['type'], $data, $column/*, []*/); }
php
{ "resource": "" }
q6758
Schema._cast
train
public function _cast($name, $data, $options) { if ($data === null) { return; } if ($data instanceof Document) { return $data; } $class = ltrim($options['class'], '\\'); $config = [ 'schema' => $class === Document::class ? $this : null, 'basePath' => $options['basePath'], 'exists' => $options['exists'], 'defaults' => $options['defaults'] ]; if (isset($options['config'])){ $config = Set::extend($config, $options['config']); } $column = isset($this->_columns[$name]) ? $this->_columns[$name] : []; if (!empty($column['format'])) { $data = $this->convert('cast', $column['format'], $data, $column, $config); } return $class::create($data ? $data : [], $config); }
php
{ "resource": "" }
q6759
Schema._castArray
train
public function _castArray($name, $data, $options) { $options['type'] = isset($options['relation']) && $options['relation'] === 'hasManyThrough' ? 'through' : 'set'; $class = ltrim($options['class'], '\\'); $classes = $class::classes(); $collection = $classes[$options['type']]; if ($data instanceof $collection) { return $data; } $isThrough = $options['type'] === 'through'; $isDocument = $class === Document::class; $config = [ 'schema' => $isDocument ? $this : $class::definition(), 'basePath' => $isDocument ? $name : null, 'meta' => isset($options['meta']) ? $options['meta'] : [], 'exists' => $options['exists'], 'defaults' => $options['defaults'] ]; if (isset($options['config'])){ $config = Set::extend($config, $options['config']); } $column = isset($this->_columns[$name]) ? $this->_columns[$name] : []; if (!empty($column['format']) && $data !== null) { $type = $column['format']; $data = $this->convert('cast', $type, $data, $column, $config); } if ($isThrough) { $config['parent'] = $options['parent']; $config['through'] = $options['through']; $config['using'] = $options['using']; $config['data'] = $data; } else { $config['data'] = $data ?: []; } return new $collection($config); }
php
{ "resource": "" }
q6760
Schema.format
train
public function format($mode, $name, $data) { if ($mode === 'cast') { throw new InvalidArgumentException("Use `Schema::cast()` to perform casting."); } if (!isset($this->_columns[$name])) { // Formatting non defined columns or relations doesn't make sense, bailing out. return $this->convert($mode, '_default_', $data, []); } $column = $this->_columns[$name]; $isNull = $data === null; $type = $isNull ? 'null' : $this->type($name); if (!$column['array']) { $data = $this->convert($mode, $type, $data, $column); } else { $data = Collection::format($mode, $data); } if (!$isNull && !empty($column['format'])) { $data = $this->convert($mode, $column['format'], $data, $column); } return $data; }
php
{ "resource": "" }
q6761
Schema.convert
train
public function convert($mode, $type, $data, $column = [], $options = []) { $formatter = null; $type = $data === null ? 'null' : $type; if (isset($this->_formatters[$mode][$type])) { $formatter = $this->_formatters[$mode][$type]; } elseif (isset($this->_formatters[$mode]['_default_'])) { $formatter = $this->_formatters[$mode]['_default_']; } return $formatter ? $formatter($data, $column, $options) : $data; }
php
{ "resource": "" }
q6762
Schema.saveRelation
train
public function saveRelation($instance, $types, $options = []) { $defaults = ['embed' => []]; $options += $defaults; $types = (array) $types; $collection = $instance instanceof Document ? [$instance] : $instance; $success = true; foreach ($collection as $entity) { foreach ($types as $type) { foreach ($options['embed'] as $relName => $value) { if (!($rel = $this->relation($relName)) || $rel->type() !== $type) { continue; } $success = $success && $rel->save($entity, $value ? $value + $options : $options); } } } return $success; }
php
{ "resource": "" }
q6763
EntryPromise.getField
train
public function getField($key) { $resolved = $this->getResolved(); if (!$resolved instanceof EntryInterface) { return null; } return $resolved->getField($key); }
php
{ "resource": "" }
q6764
StringBuffer.appendTab
train
public function appendTab($str=null, $tabNum=1) { $tab = ""; for ( $i = 0; $i < $tabNum; $i++ ) { $tab .= "\t"; } $this->appendLine($tab.$str); }
php
{ "resource": "" }
q6765
AttributeTypeQuery.filterByHasAttributeAvValue
train
public function filterByHasAttributeAvValue($hasAttributeAvValue = null, $comparison = null) { if (is_array($hasAttributeAvValue)) { $useMinMax = false; if (isset($hasAttributeAvValue['min'])) { $this->addUsingAlias(AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE, $hasAttributeAvValue['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($hasAttributeAvValue['max'])) { $this->addUsingAlias(AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE, $hasAttributeAvValue['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { return $this; } if (null === $comparison) { $comparison = Criteria::IN; } } return $this->addUsingAlias(AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE, $hasAttributeAvValue, $comparison); }
php
{ "resource": "" }
q6766
AttributeTypeQuery.filterByIsMultilingualAttributeAvValue
train
public function filterByIsMultilingualAttributeAvValue($isMultilingualAttributeAvValue = null, $comparison = null) { if (is_array($isMultilingualAttributeAvValue)) { $useMinMax = false; if (isset($isMultilingualAttributeAvValue['min'])) { $this->addUsingAlias(AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, $isMultilingualAttributeAvValue['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($isMultilingualAttributeAvValue['max'])) { $this->addUsingAlias(AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, $isMultilingualAttributeAvValue['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { return $this; } if (null === $comparison) { $comparison = Criteria::IN; } } return $this->addUsingAlias(AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, $isMultilingualAttributeAvValue, $comparison); }
php
{ "resource": "" }
q6767
AttributeTypeQuery.filterByPattern
train
public function filterByPattern($pattern = null, $comparison = null) { if (null === $comparison) { if (is_array($pattern)) { $comparison = Criteria::IN; } elseif (preg_match('/[\%\*]/', $pattern)) { $pattern = str_replace('*', '%', $pattern); $comparison = Criteria::LIKE; } } return $this->addUsingAlias(AttributeTypeTableMap::PATTERN, $pattern, $comparison); }
php
{ "resource": "" }
q6768
AttributeTypeQuery.filterByImageRatio
train
public function filterByImageRatio($imageRatio = null, $comparison = null) { if (is_array($imageRatio)) { $useMinMax = false; if (isset($imageRatio['min'])) { $this->addUsingAlias(AttributeTypeTableMap::IMAGE_RATIO, $imageRatio['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($imageRatio['max'])) { $this->addUsingAlias(AttributeTypeTableMap::IMAGE_RATIO, $imageRatio['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { return $this; } if (null === $comparison) { $comparison = Criteria::IN; } } return $this->addUsingAlias(AttributeTypeTableMap::IMAGE_RATIO, $imageRatio, $comparison); }
php
{ "resource": "" }
q6769
AttributeTypeQuery.filterByAttributeTypeI18n
train
public function filterByAttributeTypeI18n($attributeTypeI18n, $comparison = null) { if ($attributeTypeI18n instanceof \AttributeType\Model\AttributeTypeI18n) { return $this ->addUsingAlias(AttributeTypeTableMap::ID, $attributeTypeI18n->getId(), $comparison); } elseif ($attributeTypeI18n instanceof ObjectCollection) { return $this ->useAttributeTypeI18nQuery() ->filterByPrimaryKeys($attributeTypeI18n->getPrimaryKeys()) ->endUse(); } else { throw new PropelException('filterByAttributeTypeI18n() only accepts arguments of type \AttributeType\Model\AttributeTypeI18n or Collection'); } }
php
{ "resource": "" }
q6770
AttributeTypeQuery.useAttributeTypeI18nQuery
train
public function useAttributeTypeI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') { return $this ->joinAttributeTypeI18n($relationAlias, $joinType) ->useQuery($relationAlias ? $relationAlias : 'AttributeTypeI18n', '\AttributeType\Model\AttributeTypeI18nQuery'); }
php
{ "resource": "" }
q6771
AttributeTypeI18nQuery.create
train
public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof \AttributeType\Model\AttributeTypeI18nQuery) { return $criteria; } $query = new \AttributeType\Model\AttributeTypeI18nQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
php
{ "resource": "" }
q6772
CurrencyConverter.validate
train
private function validate() { if (null === $this->provider) { throw new MissingProviderException('A provider must be set for converting a currency'); } if (null === $this->from || null === $this->to) { throw new \RuntimeException('from and to parameters must be provided'); } }
php
{ "resource": "" }
q6773
ZookeeperClient.set
train
public function set($path, $value) { if (!$this->zookeeper->exists($path)) { $this->makePath($path); $this->makeNode($path, $value); } else { $this->zookeeper->set($path, $value); } }
php
{ "resource": "" }
q6774
ZookeeperClient.makePath
train
public function makePath($path, $value = '') { $parts = explode('/', $path); $parts = array_filter($parts); $subpath = ''; while (count($parts) > 1) { $subpath .= '/' . array_shift($parts); if (!$this->zookeeper->exists($subpath)) { $this->makeNode($subpath, $value); } } }
php
{ "resource": "" }
q6775
ZookeeperClient.makeNode
train
public function makeNode($path, $value, array $params = array()) { if (empty($params)) { $params = array( array( 'perms' => \Zookeeper::PERM_ALL, 'scheme' => 'world', 'id' => 'anyone', ) ); } return $this->zookeeper->create($path, $value, $params); }
php
{ "resource": "" }
q6776
ZookeeperClient.get
train
public function get($path) { if (!$this->zookeeper->exists($path)) { return null; } return $this->zookeeper->get($path); }
php
{ "resource": "" }
q6777
ZookeeperClient.getChildren
train
public function getChildren($path) { if (strlen($path) > 1 && preg_match('@/$@', $path)) { // remove trailing / $path = substr($path, 0, -1); } return $this->zookeeper->getChildren($path); }
php
{ "resource": "" }
q6778
ZookeeperClient.deleteNode
train
public function deleteNode($path) { if(!$this->zookeeper->exists($path)) { return null; } else { return $this->zookeeper->delete($path); } }
php
{ "resource": "" }
q6779
ZookeeperClient.watch
train
public function watch($path, $callback) { if (!is_callable($callback)) { return null; } if ($this->zookeeper->exists($path)) { if (!isset($this->callback[$path])) { $this->callback[$path] = array(); } if (!in_array($callback, $this->callback[$path])) { $this->callback[$path][] = $callback; return $this->zookeeper->get($path, array($this, 'watchCallback')); } } }
php
{ "resource": "" }
q6780
ZookeeperClient.watchCallback
train
public function watchCallback($event_type, $stat, $path) { if (!isset($this->callback[$path])) { return null; } foreach ($this->callback[$path] as $callback) { $this->zookeeper->get($path, array($this, 'watchCallback')); return call_user_func($callback); } }
php
{ "resource": "" }
q6781
ZookeeperClient.loadNode
train
public function loadNode($path) { $list = @$this->zookeeper->getChildren($path); if(!empty($list)) { $data = []; foreach($list as $key) { $value = $this->zookeeper->get($path . '/' . $key); if(!empty($value)) { $data[$key] = $value; }else { $data[$key] = $this->loadNode($path . '/' . $key); } } return $data; }else { $value = @$this->zookeeper->get($path); return $value; } }
php
{ "resource": "" }
q6782
Conventions.config
train
public function config($config = []) { $defaults = [ 'conventions' => [ 'source' => function($class) { $basename = substr(strrchr($class, '\\'), 1); return Inflector::underscore($basename); }, 'key' => function() { return 'id'; }, 'reference' => function($class) { $pos = strrpos($class, '\\'); $basename = substr($class, $pos !== false ? $pos + 1 : 0); return Inflector::underscore(Inflector::singularize($basename)). '_id'; }, 'references' => function($class) { $pos = strrpos($class, '\\'); $basename = substr($class, $pos !== false ? $pos + 1 : 0); return Inflector::underscore(Inflector::singularize($basename)). '_ids'; }, 'field' => function($class) { $pos = strrpos($class, '\\'); $basename = substr($class, $pos !== false ? $pos + 1 : 0); return Inflector::underscore(Inflector::singularize($basename)); }, 'multiple' => function($name) { return Inflector::pluralize($name); }, 'single' => function($name) { return Inflector::singularize($name); } ] ]; $config = Set::extend($defaults, $config); $this->_conventions = $config['conventions']; }
php
{ "resource": "" }
q6783
Conventions.get
train
public function get($name = null) { if (!$name) { return $this->_conventions; } if (!isset($this->_conventions[$name])) { throw new ORMException("Convention for `'{$name}'` doesn't exists."); } return $this->_conventions[$name]; }
php
{ "resource": "" }
q6784
Conventions.apply
train
public function apply($name) { $params = func_get_args(); array_shift($params); $convention = $this->get($name); return call_user_func_array($convention, $params); }
php
{ "resource": "" }
q6785
ScriptEngineType.toArray
train
public function toArray() { return [ 'name' => $this->name, 'label' => $this->label, 'description' => $this->description, 'sandboxed' => $this->sandboxed, 'supports_inline_execution' => $this->supportsInlineExecution, ]; }
php
{ "resource": "" }
q6786
HasMany.junction
train
public function junction($boolean = null) { if (func_num_args()) { $this->_junction = $boolean; return $this; } return $this->_junction; }
php
{ "resource": "" }
q6787
Eloquent.saveIfExists
train
public function saveIfExists(array $options = []): bool { if ($this->exists === false) { return false; } return $this->save($options); }
php
{ "resource": "" }
q6788
Eloquent.saveIfExistsOrFail
train
public function saveIfExistsOrFail(array $options = []): bool { if ($this->exists === false) { return false; } return $this->saveOrFail($options); }
php
{ "resource": "" }
q6789
TreeCore.loadRawOrder
train
protected function loadRawOrder($tmpSubTier) { $nID = $tmpSubTier[0]; $this->nodesRawIndex[$nID] = sizeof($this->nodesRawOrder); $this->nodesRawOrder[] = $nID; if (sizeof($tmpSubTier[1]) > 0) { foreach ($tmpSubTier[1] as $deeper) { $this->loadRawOrder($deeper); } } return true; }
php
{ "resource": "" }
q6790
TreeCore.prevNode
train
public function prevNode($nID) { $nodeOverride = $this->movePrevOverride($nID); if ($nodeOverride > 0) { return $nodeOverride; } if (!isset($this->nodesRawIndex[$nID])) { return -3; } $prevNodeInd = $this->nodesRawIndex[$nID]-1; if ($prevNodeInd < 0 || !isset($this->nodesRawOrder[$prevNodeInd])) { return -3; } $prevNodeID = $this->nodesRawOrder[$prevNodeInd]; return $prevNodeID; }
php
{ "resource": "" }
q6791
TreeCore.nextNode
train
public function nextNode($nID) { if ($nID <= 0 || !isset($this->nodesRawIndex[$nID])) { return -3; } $this->runCurrNode($nID); $nodeOverride = $this->moveNextOverride($nID); if ($nodeOverride > 0) { return $nodeOverride; } //if ($nID == $GLOBALS["SL"]->treeRow->TreeLastPage) return -37; $nextNodeInd = $this->nodesRawIndex[$nID]+1; if (!isset($this->nodesRawOrder[$nextNodeInd])) { return -3; } $nextNodeID = $this->nodesRawOrder[$nextNodeInd]; return $nextNodeID; }
php
{ "resource": "" }
q6792
TreeCore.nextNodeSibling
train
public function nextNodeSibling($nID) { //if ($nID == $this->tree->TreeLastPage) return -37; if (!$this->hasNode($nID) || $this->allNodes[$nID]->parentID <= 0) { return -3; } $nodeOverride = $this->moveNextOverride($nID); if ($nodeOverride > 0) { return $nodeOverride; } $nextSibling = SLNode::where('NodeTree', $this->treeID) ->where('NodeParentID', $this->allNodes[$nID]->parentID) ->where('NodeParentOrder', (1+$this->allNodes[$nID]->parentOrd)) ->select('NodeID') ->first(); if ($nextSibling && isset($nextSibling->NodeID)) { return $nextSibling->NodeID; } return $this->nextNodeSibling($this->allNodes[$nID]->parentID); }
php
{ "resource": "" }
q6793
TreeCore.updateCurrNode
train
public function updateCurrNode($nID = -3) { if ($nID > 0) { if (!isset($GLOBALS["SL"]->formTree->TreeID)) { if (!$this->sessInfo) { $this->createNewSess(); } $this->sessInfo->SessCurrNode = $nID; $this->sessInfo->save(); if ($GLOBALS["SL"]->coreTblAbbr() != '' && isset($this->sessData->dataSets[$GLOBALS["SL"]->coreTbl])) { $this->sessData->currSessData($nID, $GLOBALS["SL"]->coreTbl, $GLOBALS["SL"]->coreTblAbbr() . 'SubmissionProgress', 'update', $nID); } } $this->currNodeSubTier = $this->loadNodeSubTier($nID); $this->loadNodeDataBranch($nID); } return true; }
php
{ "resource": "" }
q6794
Request.setParameters
train
public function setParameters(array $parameters, $append = false) { if (!$append) { $this->parameters = $parameters; } else { foreach ($parameters as $field => $value) { $this->setParameter($field, $value); } } }
php
{ "resource": "" }
q6795
Request.getHeader
train
public function getHeader($field) { if (!isset($this->headers[$field])) { return null; } return is_array($this->headers[$field]) ? implode(',', $this->headers[$field]) : $this->headers[$field]; }
php
{ "resource": "" }
q6796
Request.getHeaders
train
public function getHeaders() { $headerFields = array_keys($this->headers); $result = array(); foreach ($headerFields as $field) { $result[] = sprintf('%s: %s', $field, $this->getHeader($field)); } return $result; }
php
{ "resource": "" }
q6797
Request.setHeaders
train
public function setHeaders(array $headers, $append = false) { if (!$append) { $this->headers = $headers; } else { foreach ($headers as $field => $value) { $this->setHeader($field, $value); } } }
php
{ "resource": "" }
q6798
Curl.send
train
public function send(Request $request) { $curl = $this->prepareRequest($request); $data = curl_exec($curl); if (false === $data) { $errorMsg = curl_error($curl); $errorNo = curl_errno($curl); throw new \RuntimeException($errorMsg, $errorNo); } $data = $this->filterRawResponse($data); return $this->prepareResponse($data, curl_getinfo($curl, CURLINFO_HTTP_CODE)); }
php
{ "resource": "" }
q6799
Curl.prepareRequest
train
protected function prepareRequest(Request $request) { $curl = curl_init(); // TODO Timeout and Follow Redirect settings $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_CONNECTTIMEOUT_MS => 1000, CURLOPT_TIMEOUT_MS => 3000, CURLOPT_CUSTOMREQUEST => $request->getMethod(), CURLOPT_URL => $request->getUri(), CURLOPT_HTTPHEADER => $request->getHeaders(), CURLOPT_HTTPGET => false, CURLOPT_NOBODY => false, CURLOPT_POST => false, CURLOPT_POSTFIELDS => null, ); switch ($request->getMethod()) { case Request::METHOD_HEAD: $options[CURLOPT_NOBODY] = true; $query = http_build_query($request->getParameters()); if (!empty($query)) { $options[CURLOPT_URL] = $request->getUri().'?'.$query; } break; case Request::METHOD_GET: $options[CURLOPT_HTTPGET] = true; $query = http_build_query($request->getParameters()); if (!empty($query)) { $options[CURLOPT_URL] = $request->getUri().'?'.$query; } break; case Request::METHOD_POST: case Request::METHOD_PUT: $options[CURLOPT_POST] = true; $options[CURLOPT_POSTFIELDS] = http_build_query($request->getParameters()); break; } curl_setopt_array($curl, $options); return $curl; }
php
{ "resource": "" }