_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q242300 | BreakingChangesFinder.findValuesRemovedFromEnums | validation | public static function findValuesRemovedFromEnums(
Schema $oldSchema,
Schema $newSchema
) {
$oldTypeMap = $oldSchema->getTypeMap();
$newTypeMap = $newSchema->getTypeMap();
$valuesRemovedFromEnums = [];
foreach ($oldTypeMap as $typeName => $oldType) {
$newType = $newTypeMap[$typeName] ?? null;
if (! ($oldType instanceof EnumType) || ! ($newType instanceof EnumType)) {
continue;
}
$valuesInNewEnum = [];
foreach ($newType->getValues() as $value) {
$valuesInNewEnum[$value->name] = true;
}
foreach ($oldType->getValues() as $value) {
if (isset($valuesInNewEnum[$value->name])) {
continue;
}
$valuesRemovedFromEnums[] = [
'type' => self::BREAKING_CHANGE_VALUE_REMOVED_FROM_ENUM,
'description' => sprintf('%s was removed from enum type %s.', $value->name, $typeName),
];
}
}
return $valuesRemovedFromEnums;
} | php | {
"resource": ""
} |
q242301 | BreakingChangesFinder.findDangerousChanges | validation | public static function findDangerousChanges(Schema $oldSchema, Schema $newSchema)
{
return array_merge(
self::findArgChanges($oldSchema, $newSchema)['dangerousChanges'],
self::findValuesAddedToEnums($oldSchema, $newSchema),
self::findInterfacesAddedToObjectTypes($oldSchema, $newSchema),
self::findTypesAddedToUnions($oldSchema, $newSchema),
self::findFieldsThatChangedTypeOnInputObjectTypes($oldSchema, $newSchema)['dangerousChanges']
);
} | php | {
"resource": ""
} |
q242302 | BreakingChangesFinder.findValuesAddedToEnums | validation | public static function findValuesAddedToEnums(
Schema $oldSchema,
Schema $newSchema
) {
$oldTypeMap = $oldSchema->getTypeMap();
$newTypeMap = $newSchema->getTypeMap();
$valuesAddedToEnums = [];
foreach ($oldTypeMap as $typeName => $oldType) {
$newType = $newTypeMap[$typeName] ?? null;
if (! ($oldType instanceof EnumType) || ! ($newType instanceof EnumType)) {
continue;
}
$valuesInOldEnum = [];
foreach ($oldType->getValues() as $value) {
$valuesInOldEnum[$value->name] = true;
}
foreach ($newType->getValues() as $value) {
if (isset($valuesInOldEnum[$value->name])) {
continue;
}
$valuesAddedToEnums[] = [
'type' => self::DANGEROUS_CHANGE_VALUE_ADDED_TO_ENUM,
'description' => sprintf('%s was added to enum type %s.', $value->name, $typeName),
];
}
}
return $valuesAddedToEnums;
} | php | {
"resource": ""
} |
q242303 | BreakingChangesFinder.findTypesAddedToUnions | validation | public static function findTypesAddedToUnions(
Schema $oldSchema,
Schema $newSchema
) {
$oldTypeMap = $oldSchema->getTypeMap();
$newTypeMap = $newSchema->getTypeMap();
$typesAddedToUnion = [];
foreach ($newTypeMap as $typeName => $newType) {
$oldType = $oldTypeMap[$typeName] ?? null;
if (! ($oldType instanceof UnionType) || ! ($newType instanceof UnionType)) {
continue;
}
$typeNamesInOldUnion = [];
foreach ($oldType->getTypes() as $type) {
$typeNamesInOldUnion[$type->name] = true;
}
foreach ($newType->getTypes() as $type) {
if (isset($typeNamesInOldUnion[$type->name])) {
continue;
}
$typesAddedToUnion[] = [
'type' => self::DANGEROUS_CHANGE_TYPE_ADDED_TO_UNION,
'description' => sprintf('%s was added to union type %s.', $type->name, $typeName),
];
}
}
return $typesAddedToUnion;
} | php | {
"resource": ""
} |
q242304 | OverlappingFieldsCanBeMerged.findConflictsWithinSelectionSet | validation | private function findConflictsWithinSelectionSet(
ValidationContext $context,
$parentType,
SelectionSetNode $selectionSet
) {
[$fieldMap, $fragmentNames] = $this->getFieldsAndFragmentNames(
$context,
$parentType,
$selectionSet
);
$conflicts = [];
// (A) Find find all conflicts "within" the fields of this selection set.
// Note: this is the *only place* `collectConflictsWithin` is called.
$this->collectConflictsWithin(
$context,
$conflicts,
$fieldMap
);
$fragmentNamesLength = count($fragmentNames);
if ($fragmentNamesLength !== 0) {
// (B) Then collect conflicts between these fields and those represented by
// each spread fragment name found.
$comparedFragments = [];
for ($i = 0; $i < $fragmentNamesLength; $i++) {
$this->collectConflictsBetweenFieldsAndFragment(
$context,
$conflicts,
$comparedFragments,
false,
$fieldMap,
$fragmentNames[$i]
);
// (C) Then compare this fragment with all other fragments found in this
// selection set to collect conflicts between fragments spread together.
// This compares each item in the list of fragment names to every other item
// in that same list (except for itself).
for ($j = $i + 1; $j < $fragmentNamesLength; $j++) {
$this->collectConflictsBetweenFragments(
$context,
$conflicts,
false,
$fragmentNames[$i],
$fragmentNames[$j]
);
}
}
}
return $conflicts;
} | php | {
"resource": ""
} |
q242305 | OverlappingFieldsCanBeMerged.collectConflictsWithin | validation | private function collectConflictsWithin(
ValidationContext $context,
array &$conflicts,
array $fieldMap
) {
// A field map is a keyed collection, where each key represents a response
// name and the value at that key is a list of all fields which provide that
// response name. For every response name, if there are multiple fields, they
// must be compared to find a potential conflict.
foreach ($fieldMap as $responseName => $fields) {
// This compares every field in the list to every other field in this list
// (except to itself). If the list only has one item, nothing needs to
// be compared.
$fieldsLength = count($fields);
if ($fieldsLength <= 1) {
continue;
}
for ($i = 0; $i < $fieldsLength; $i++) {
for ($j = $i + 1; $j < $fieldsLength; $j++) {
$conflict = $this->findConflict(
$context,
false, // within one collection is never mutually exclusive
$responseName,
$fields[$i],
$fields[$j]
);
if (! $conflict) {
continue;
}
$conflicts[] = $conflict;
}
}
}
} | php | {
"resource": ""
} |
q242306 | OverlappingFieldsCanBeMerged.findConflict | validation | private function findConflict(
ValidationContext $context,
$parentFieldsAreMutuallyExclusive,
$responseName,
array $field1,
array $field2
) {
[$parentType1, $ast1, $def1] = $field1;
[$parentType2, $ast2, $def2] = $field2;
// If it is known that two fields could not possibly apply at the same
// time, due to the parent types, then it is safe to permit them to diverge
// in aliased field or arguments used as they will not present any ambiguity
// by differing.
// It is known that two parent types could never overlap if they are
// different Object types. Interface or Union types might overlap - if not
// in the current state of the schema, then perhaps in some future version,
// thus may not safely diverge.
$areMutuallyExclusive =
$parentFieldsAreMutuallyExclusive ||
(
$parentType1 !== $parentType2 &&
$parentType1 instanceof ObjectType &&
$parentType2 instanceof ObjectType
);
// The return type for each field.
$type1 = $def1 === null ? null : $def1->getType();
$type2 = $def2 === null ? null : $def2->getType();
if (! $areMutuallyExclusive) {
// Two aliases must refer to the same field.
$name1 = $ast1->name->value;
$name2 = $ast2->name->value;
if ($name1 !== $name2) {
return [
[$responseName, sprintf('%s and %s are different fields', $name1, $name2)],
[$ast1],
[$ast2],
];
}
if (! $this->sameArguments($ast1->arguments ?: [], $ast2->arguments ?: [])) {
return [
[$responseName, 'they have differing arguments'],
[$ast1],
[$ast2],
];
}
}
if ($type1 && $type2 && $this->doTypesConflict($type1, $type2)) {
return [
[$responseName, sprintf('they return conflicting types %s and %s', $type1, $type2)],
[$ast1],
[$ast2],
];
}
// Collect and compare sub-fields. Use the same "visited fragment names" list
// for both collections so fields in a fragment reference are never
// compared to themselves.
$selectionSet1 = $ast1->selectionSet;
$selectionSet2 = $ast2->selectionSet;
if ($selectionSet1 && $selectionSet2) {
$conflicts = $this->findConflictsBetweenSubSelectionSets(
$context,
$areMutuallyExclusive,
Type::getNamedType($type1),
$selectionSet1,
Type::getNamedType($type2),
$selectionSet2
);
return $this->subfieldConflicts(
$conflicts,
$responseName,
$ast1,
$ast2
);
}
return null;
} | php | {
"resource": ""
} |
q242307 | OverlappingFieldsCanBeMerged.doTypesConflict | validation | private function doTypesConflict(OutputType $type1, OutputType $type2)
{
if ($type1 instanceof ListOfType) {
return $type2 instanceof ListOfType ?
$this->doTypesConflict($type1->getWrappedType(), $type2->getWrappedType()) :
true;
}
if ($type2 instanceof ListOfType) {
return $type1 instanceof ListOfType ?
$this->doTypesConflict($type1->getWrappedType(), $type2->getWrappedType()) :
true;
}
if ($type1 instanceof NonNull) {
return $type2 instanceof NonNull ?
$this->doTypesConflict($type1->getWrappedType(), $type2->getWrappedType()) :
true;
}
if ($type2 instanceof NonNull) {
return $type1 instanceof NonNull ?
$this->doTypesConflict($type1->getWrappedType(), $type2->getWrappedType()) :
true;
}
if (Type::isLeafType($type1) || Type::isLeafType($type2)) {
return $type1 !== $type2;
}
return false;
} | php | {
"resource": ""
} |
q242308 | OverlappingFieldsCanBeMerged.findConflictsBetweenSubSelectionSets | validation | private function findConflictsBetweenSubSelectionSets(
ValidationContext $context,
$areMutuallyExclusive,
$parentType1,
SelectionSetNode $selectionSet1,
$parentType2,
SelectionSetNode $selectionSet2
) {
$conflicts = [];
[$fieldMap1, $fragmentNames1] = $this->getFieldsAndFragmentNames(
$context,
$parentType1,
$selectionSet1
);
[$fieldMap2, $fragmentNames2] = $this->getFieldsAndFragmentNames(
$context,
$parentType2,
$selectionSet2
);
// (H) First, collect all conflicts between these two collections of field.
$this->collectConflictsBetween(
$context,
$conflicts,
$areMutuallyExclusive,
$fieldMap1,
$fieldMap2
);
// (I) Then collect conflicts between the first collection of fields and
// those referenced by each fragment name associated with the second.
$fragmentNames2Length = count($fragmentNames2);
if ($fragmentNames2Length !== 0) {
$comparedFragments = [];
for ($j = 0; $j < $fragmentNames2Length; $j++) {
$this->collectConflictsBetweenFieldsAndFragment(
$context,
$conflicts,
$comparedFragments,
$areMutuallyExclusive,
$fieldMap1,
$fragmentNames2[$j]
);
}
}
// (I) Then collect conflicts between the second collection of fields and
// those referenced by each fragment name associated with the first.
$fragmentNames1Length = count($fragmentNames1);
if ($fragmentNames1Length !== 0) {
$comparedFragments = [];
for ($i = 0; $i < $fragmentNames1Length; $i++) {
$this->collectConflictsBetweenFieldsAndFragment(
$context,
$conflicts,
$comparedFragments,
$areMutuallyExclusive,
$fieldMap2,
$fragmentNames1[$i]
);
}
}
// (J) Also collect conflicts between any fragment names by the first and
// fragment names by the second. This compares each item in the first set of
// names to each item in the second set of names.
for ($i = 0; $i < $fragmentNames1Length; $i++) {
for ($j = 0; $j < $fragmentNames2Length; $j++) {
$this->collectConflictsBetweenFragments(
$context,
$conflicts,
$areMutuallyExclusive,
$fragmentNames1[$i],
$fragmentNames2[$j]
);
}
}
return $conflicts;
} | php | {
"resource": ""
} |
q242309 | OverlappingFieldsCanBeMerged.collectConflictsBetween | validation | private function collectConflictsBetween(
ValidationContext $context,
array &$conflicts,
$parentFieldsAreMutuallyExclusive,
array $fieldMap1,
array $fieldMap2
) {
// A field map is a keyed collection, where each key represents a response
// name and the value at that key is a list of all fields which provide that
// response name. For any response name which appears in both provided field
// maps, each field from the first field map must be compared to every field
// in the second field map to find potential conflicts.
foreach ($fieldMap1 as $responseName => $fields1) {
if (! isset($fieldMap2[$responseName])) {
continue;
}
$fields2 = $fieldMap2[$responseName];
$fields1Length = count($fields1);
$fields2Length = count($fields2);
for ($i = 0; $i < $fields1Length; $i++) {
for ($j = 0; $j < $fields2Length; $j++) {
$conflict = $this->findConflict(
$context,
$parentFieldsAreMutuallyExclusive,
$responseName,
$fields1[$i],
$fields2[$j]
);
if (! $conflict) {
continue;
}
$conflicts[] = $conflict;
}
}
}
} | php | {
"resource": ""
} |
q242310 | OverlappingFieldsCanBeMerged.collectConflictsBetweenFieldsAndFragment | validation | private function collectConflictsBetweenFieldsAndFragment(
ValidationContext $context,
array &$conflicts,
array &$comparedFragments,
$areMutuallyExclusive,
array $fieldMap,
$fragmentName
) {
if (isset($comparedFragments[$fragmentName])) {
return;
}
$comparedFragments[$fragmentName] = true;
$fragment = $context->getFragment($fragmentName);
if (! $fragment) {
return;
}
[$fieldMap2, $fragmentNames2] = $this->getReferencedFieldsAndFragmentNames(
$context,
$fragment
);
if ($fieldMap === $fieldMap2) {
return;
}
// (D) First collect any conflicts between the provided collection of fields
// and the collection of fields represented by the given fragment.
$this->collectConflictsBetween(
$context,
$conflicts,
$areMutuallyExclusive,
$fieldMap,
$fieldMap2
);
// (E) Then collect any conflicts between the provided collection of fields
// and any fragment names found in the given fragment.
$fragmentNames2Length = count($fragmentNames2);
for ($i = 0; $i < $fragmentNames2Length; $i++) {
$this->collectConflictsBetweenFieldsAndFragment(
$context,
$conflicts,
$comparedFragments,
$areMutuallyExclusive,
$fieldMap,
$fragmentNames2[$i]
);
}
} | php | {
"resource": ""
} |
q242311 | OverlappingFieldsCanBeMerged.collectConflictsBetweenFragments | validation | private function collectConflictsBetweenFragments(
ValidationContext $context,
array &$conflicts,
$areMutuallyExclusive,
$fragmentName1,
$fragmentName2
) {
// No need to compare a fragment to itself.
if ($fragmentName1 === $fragmentName2) {
return;
}
// Memoize so two fragments are not compared for conflicts more than once.
if ($this->comparedFragmentPairs->has(
$fragmentName1,
$fragmentName2,
$areMutuallyExclusive
)
) {
return;
}
$this->comparedFragmentPairs->add(
$fragmentName1,
$fragmentName2,
$areMutuallyExclusive
);
$fragment1 = $context->getFragment($fragmentName1);
$fragment2 = $context->getFragment($fragmentName2);
if (! $fragment1 || ! $fragment2) {
return;
}
[$fieldMap1, $fragmentNames1] = $this->getReferencedFieldsAndFragmentNames(
$context,
$fragment1
);
[$fieldMap2, $fragmentNames2] = $this->getReferencedFieldsAndFragmentNames(
$context,
$fragment2
);
// (F) First, collect all conflicts between these two collections of fields
// (not including any nested fragments).
$this->collectConflictsBetween(
$context,
$conflicts,
$areMutuallyExclusive,
$fieldMap1,
$fieldMap2
);
// (G) Then collect conflicts between the first fragment and any nested
// fragments spread in the second fragment.
$fragmentNames2Length = count($fragmentNames2);
for ($j = 0; $j < $fragmentNames2Length; $j++) {
$this->collectConflictsBetweenFragments(
$context,
$conflicts,
$areMutuallyExclusive,
$fragmentName1,
$fragmentNames2[$j]
);
}
// (G) Then collect conflicts between the second fragment and any nested
// fragments spread in the first fragment.
$fragmentNames1Length = count($fragmentNames1);
for ($i = 0; $i < $fragmentNames1Length; $i++) {
$this->collectConflictsBetweenFragments(
$context,
$conflicts,
$areMutuallyExclusive,
$fragmentNames1[$i],
$fragmentName2
);
}
} | php | {
"resource": ""
} |
q242312 | OverlappingFieldsCanBeMerged.subfieldConflicts | validation | private function subfieldConflicts(
array $conflicts,
$responseName,
FieldNode $ast1,
FieldNode $ast2
) {
if (count($conflicts) === 0) {
return null;
}
return [
[
$responseName,
array_map(
static function ($conflict) {
return $conflict[0];
},
$conflicts
),
],
array_reduce(
$conflicts,
static function ($allFields, $conflict) {
return array_merge($allFields, $conflict[1]);
},
[$ast1]
),
array_reduce(
$conflicts,
static function ($allFields, $conflict) {
return array_merge($allFields, $conflict[2]);
},
[$ast2]
),
];
} | php | {
"resource": ""
} |
q242313 | FieldsOnCorrectType.getSuggestedTypeNames | validation | private function getSuggestedTypeNames(Schema $schema, $type, $fieldName)
{
if (Type::isAbstractType($type)) {
$suggestedObjectTypes = [];
$interfaceUsageCount = [];
foreach ($schema->getPossibleTypes($type) as $possibleType) {
$fields = $possibleType->getFields();
if (! isset($fields[$fieldName])) {
continue;
}
// This object type defines this field.
$suggestedObjectTypes[] = $possibleType->name;
foreach ($possibleType->getInterfaces() as $possibleInterface) {
$fields = $possibleInterface->getFields();
if (! isset($fields[$fieldName])) {
continue;
}
// This interface type defines this field.
$interfaceUsageCount[$possibleInterface->name] =
! isset($interfaceUsageCount[$possibleInterface->name])
? 0
: $interfaceUsageCount[$possibleInterface->name] + 1;
}
}
// Suggest interface types based on how common they are.
arsort($interfaceUsageCount);
$suggestedInterfaceTypes = array_keys($interfaceUsageCount);
// Suggest both interface and object types.
return array_merge($suggestedInterfaceTypes, $suggestedObjectTypes);
}
// Otherwise, must be an Object type, which does not have possible fields.
return [];
} | php | {
"resource": ""
} |
q242314 | FieldsOnCorrectType.getSuggestedFieldNames | validation | private function getSuggestedFieldNames(Schema $schema, $type, $fieldName)
{
if ($type instanceof ObjectType || $type instanceof InterfaceType) {
$possibleFieldNames = array_keys($type->getFields());
return Utils::suggestionList($fieldName, $possibleFieldNames);
}
// Otherwise, must be a Union type, which does not define fields.
return [];
} | php | {
"resource": ""
} |
q242315 | ExecutionResult.toArray | validation | public function toArray($debug = false)
{
$result = [];
if (! empty($this->errors)) {
$errorsHandler = $this->errorsHandler ?: static function (array $errors, callable $formatter) {
return array_map($formatter, $errors);
};
$result['errors'] = $errorsHandler(
$this->errors,
FormattedError::prepareFormatter($this->errorFormatter, $debug)
);
}
if ($this->data !== null) {
$result['data'] = $this->data;
}
if (! empty($this->extensions)) {
$result['extensions'] = $this->extensions;
}
return $result;
} | php | {
"resource": ""
} |
q242316 | AST.fromArray | validation | public static function fromArray(array $node) : Node
{
if (! isset($node['kind']) || ! isset(NodeKind::$classMap[$node['kind']])) {
throw new InvariantViolation('Unexpected node structure: ' . Utils::printSafeJson($node));
}
$kind = $node['kind'] ?? null;
$class = NodeKind::$classMap[$kind];
$instance = new $class([]);
if (isset($node['loc'], $node['loc']['start'], $node['loc']['end'])) {
$instance->loc = Location::create($node['loc']['start'], $node['loc']['end']);
}
foreach ($node as $key => $value) {
if ($key === 'loc' || $key === 'kind') {
continue;
}
if (is_array($value)) {
if (isset($value[0]) || empty($value)) {
$value = new NodeList($value);
} else {
$value = self::fromArray($value);
}
}
$instance->{$key} = $value;
}
return $instance;
} | php | {
"resource": ""
} |
q242317 | AST.isMissingVariable | validation | private static function isMissingVariable($valueNode, $variables)
{
return $valueNode instanceof VariableNode &&
(count($variables) === 0 || ! array_key_exists($valueNode->name->value, $variables));
} | php | {
"resource": ""
} |
q242318 | AST.typeFromAST | validation | public static function typeFromAST(Schema $schema, $inputTypeNode)
{
if ($inputTypeNode instanceof ListTypeNode) {
$innerType = self::typeFromAST($schema, $inputTypeNode->type);
return $innerType ? new ListOfType($innerType) : null;
}
if ($inputTypeNode instanceof NonNullTypeNode) {
$innerType = self::typeFromAST($schema, $inputTypeNode->type);
return $innerType ? new NonNull($innerType) : null;
}
if ($inputTypeNode instanceof NamedTypeNode) {
return $schema->getType($inputTypeNode->name->value);
}
throw new Error('Unexpected type kind: ' . $inputTypeNode->kind . '.');
} | php | {
"resource": ""
} |
q242319 | GraphQL.executeQuery | validation | public static function executeQuery(
SchemaType $schema,
$source,
$rootValue = null,
$context = null,
$variableValues = null,
?string $operationName = null,
?callable $fieldResolver = null,
?array $validationRules = null
) : ExecutionResult {
$promiseAdapter = new SyncPromiseAdapter();
$promise = self::promiseToExecute(
$promiseAdapter,
$schema,
$source,
$rootValue,
$context,
$variableValues,
$operationName,
$fieldResolver,
$validationRules
);
return $promiseAdapter->wait($promise);
} | php | {
"resource": ""
} |
q242320 | Warning.enable | validation | public static function enable($enable = true)
{
if ($enable === true) {
self::$enableWarnings = self::ALL;
} elseif ($enable === false) {
self::$enableWarnings = 0;
} else {
self::$enableWarnings |= $enable;
}
} | php | {
"resource": ""
} |
q242321 | Parser.parse | validation | public static function parse($source, array $options = [])
{
$sourceObj = $source instanceof Source ? $source : new Source($source);
$parser = new self($sourceObj, $options);
return $parser->parseDocument();
} | php | {
"resource": ""
} |
q242322 | Parser.loc | validation | private function loc(Token $startToken)
{
if (empty($this->lexer->options['noLocation'])) {
return new Location($startToken, $this->lexer->lastToken, $this->lexer->source);
}
return null;
} | php | {
"resource": ""
} |
q242323 | Parser.skip | validation | private function skip($kind)
{
$match = $this->lexer->token->kind === $kind;
if ($match) {
$this->lexer->advance();
}
return $match;
} | php | {
"resource": ""
} |
q242324 | Parser.expect | validation | private function expect($kind)
{
$token = $this->lexer->token;
if ($token->kind === $kind) {
$this->lexer->advance();
return $token;
}
throw new SyntaxError(
$this->lexer->source,
$token->start,
sprintf('Expected %s, found %s', $kind, $token->getDescription())
);
} | php | {
"resource": ""
} |
q242325 | Parser.expectKeyword | validation | private function expectKeyword($value)
{
$token = $this->lexer->token;
if ($token->kind === Token::NAME && $token->value === $value) {
$this->lexer->advance();
return $token;
}
throw new SyntaxError(
$this->lexer->source,
$token->start,
'Expected "' . $value . '", found ' . $token->getDescription()
);
} | php | {
"resource": ""
} |
q242326 | Parser.parseName | validation | private function parseName()
{
$token = $this->expect(Token::NAME);
return new NameNode([
'value' => $token->value,
'loc' => $this->loc($token),
]);
} | php | {
"resource": ""
} |
q242327 | Parser.parseDocument | validation | private function parseDocument()
{
$start = $this->lexer->token;
$this->expect(Token::SOF);
$definitions = [];
do {
$definitions[] = $this->parseDefinition();
} while (! $this->skip(Token::EOF));
return new DocumentNode([
'definitions' => new NodeList($definitions),
'loc' => $this->loc($start),
]);
} | php | {
"resource": ""
} |
q242328 | TypeInfo.extractTypes | validation | public static function extractTypes($type, ?array $typeMap = null)
{
if (! $typeMap) {
$typeMap = [];
}
if (! $type) {
return $typeMap;
}
if ($type instanceof WrappingType) {
return self::extractTypes($type->getWrappedType(true), $typeMap);
}
if (! $type instanceof Type) {
// Preserve these invalid types in map (at numeric index) to make them
// detectable during $schema->validate()
$i = 0;
$alreadyInMap = false;
while (isset($typeMap[$i])) {
$alreadyInMap = $alreadyInMap || $typeMap[$i] === $type;
$i++;
}
if (! $alreadyInMap) {
$typeMap[$i] = $type;
}
return $typeMap;
}
if (! empty($typeMap[$type->name])) {
Utils::invariant(
$typeMap[$type->name] === $type,
sprintf('Schema must contain unique named types but contains multiple types named "%s" ', $type) .
'(see http://webonyx.github.io/graphql-php/type-system/#type-registry).'
);
return $typeMap;
}
$typeMap[$type->name] = $type;
$nestedTypes = [];
if ($type instanceof UnionType) {
$nestedTypes = $type->getTypes();
}
if ($type instanceof ObjectType) {
$nestedTypes = array_merge($nestedTypes, $type->getInterfaces());
}
if ($type instanceof ObjectType || $type instanceof InterfaceType) {
foreach ($type->getFields() as $fieldName => $field) {
if (! empty($field->args)) {
$fieldArgTypes = array_map(
static function (FieldArgument $arg) {
return $arg->getType();
},
$field->args
);
$nestedTypes = array_merge($nestedTypes, $fieldArgTypes);
}
$nestedTypes[] = $field->getType();
}
}
if ($type instanceof InputObjectType) {
foreach ($type->getFields() as $fieldName => $field) {
$nestedTypes[] = $field->getType();
}
}
foreach ($nestedTypes as $nestedType) {
$typeMap = self::extractTypes($nestedType, $typeMap);
}
return $typeMap;
} | php | {
"resource": ""
} |
q242329 | TypeInfo.getFieldDefinition | validation | private static function getFieldDefinition(Schema $schema, Type $parentType, FieldNode $fieldNode)
{
$name = $fieldNode->name->value;
$schemaMeta = Introspection::schemaMetaFieldDef();
if ($name === $schemaMeta->name && $schema->getQueryType() === $parentType) {
return $schemaMeta;
}
$typeMeta = Introspection::typeMetaFieldDef();
if ($name === $typeMeta->name && $schema->getQueryType() === $parentType) {
return $typeMeta;
}
$typeNameMeta = Introspection::typeNameMetaFieldDef();
if ($name === $typeNameMeta->name && $parentType instanceof CompositeType) {
return $typeNameMeta;
}
if ($parentType instanceof ObjectType ||
$parentType instanceof InterfaceType) {
$fields = $parentType->getFields();
return $fields[$name] ?? null;
}
return null;
} | php | {
"resource": ""
} |
q242330 | Generator.getStub | validation | protected function getStub($name) {
if ( stripos($name, '.php') === FALSE )
$name = $name . '.php';
return $this->files->get($this->getStubPath() . '/' . $name);
} | php | {
"resource": ""
} |
q242331 | Builder.reOrderBy | validation | public function reOrderBy($column, $direction = 'asc') {
$this->orders = null;
if ( !is_null($column) ) return $this->orderBy($column, $direction);
return $this;
} | php | {
"resource": ""
} |
q242332 | Builder.aggregate | validation | public function aggregate($function, $columns = array('*')) {
// Postgres doesn't like ORDER BY when there's no GROUP BY clause
if ( !isset($this->groups) )
$this->reOrderBy(null);
return parent::aggregate($function, $columns);
} | php | {
"resource": ""
} |
q242333 | Model.reload | validation | public function reload() {
if ( $this->exists || ($this->areSoftDeletesEnabled() && $this->trashed()) ) {
$fresh = $this->getFreshInstance();
if ( is_null($fresh) )
throw with(new ModelNotFoundException)->setModel(get_called_class());
$this->setRawAttributes($fresh->getAttributes(), true);
$this->setRelations($fresh->getRelations());
$this->exists = $fresh->exists;
} else {
// Revert changes if model is not persisted
$this->attributes = $this->original;
}
return $this;
} | php | {
"resource": ""
} |
q242334 | Model.getFreshInstance | validation | protected function getFreshInstance() {
if ( $this->areSoftDeletesEnabled() )
return static::withTrashed()->find($this->getKey());
return static::find($this->getKey());
} | php | {
"resource": ""
} |
q242335 | SetBuilder.roots | validation | public function roots() {
return $this->node->newQuery()
->whereNull($this->node->getQualifiedParentColumnName())
->orderBy($this->node->getQualifiedLeftColumnName())
->orderBy($this->node->getQualifiedRightColumnName())
->orderBy($this->node->getQualifiedKeyName())
->get();
} | php | {
"resource": ""
} |
q242336 | SetBuilder.children | validation | public function children($node) {
$query = $this->node->newQuery();
$query->where($this->node->getQualifiedParentColumnName(), '=', $node->getKey());
// We must also add the scoped column values to the query to compute valid
// left and right indexes.
foreach($this->scopedAttributes($node) as $fld => $value)
$query->where($this->qualify($fld), '=', $value);
$query->orderBy($this->node->getQualifiedLeftColumnName());
$query->orderBy($this->node->getQualifiedRightColumnName());
$query->orderBy($this->node->getQualifiedKeyName());
return $query->get();
} | php | {
"resource": ""
} |
q242337 | SetBuilder.scopedAttributes | validation | protected function scopedAttributes($node) {
$keys = $this->node->getScopedColumns();
if ( count($keys) == 0 )
return array();
$values = array_map(function($column) use ($node) {
return $node->getAttribute($column); }, $keys);
return array_combine($keys, $values);
} | php | {
"resource": ""
} |
q242338 | Move.to | validation | public static function to($node, $target, $position) {
$instance = new static($node, $target, $position);
return $instance->perform();
} | php | {
"resource": ""
} |
q242339 | Move.updateStructure | validation | public function updateStructure() {
list($a, $b, $c, $d) = $this->boundaries();
// select the rows between the leftmost & the rightmost boundaries and apply a lock
$this->applyLockBetween($a, $d);
$connection = $this->node->getConnection();
$grammar = $connection->getQueryGrammar();
$currentId = $this->quoteIdentifier($this->node->getKey());
$parentId = $this->quoteIdentifier($this->parentId());
$leftColumn = $this->node->getLeftColumnName();
$rightColumn = $this->node->getRightColumnName();
$parentColumn = $this->node->getParentColumnName();
$wrappedLeft = $grammar->wrap($leftColumn);
$wrappedRight = $grammar->wrap($rightColumn);
$wrappedParent = $grammar->wrap($parentColumn);
$wrappedId = $grammar->wrap($this->node->getKeyName());
$lftSql = "CASE
WHEN $wrappedLeft BETWEEN $a AND $b THEN $wrappedLeft + $d - $b
WHEN $wrappedLeft BETWEEN $c AND $d THEN $wrappedLeft + $a - $c
ELSE $wrappedLeft END";
$rgtSql = "CASE
WHEN $wrappedRight BETWEEN $a AND $b THEN $wrappedRight + $d - $b
WHEN $wrappedRight BETWEEN $c AND $d THEN $wrappedRight + $a - $c
ELSE $wrappedRight END";
$parentSql = "CASE
WHEN $wrappedId = $currentId THEN $parentId
ELSE $wrappedParent END";
$updateConditions = array(
$leftColumn => $connection->raw($lftSql),
$rightColumn => $connection->raw($rgtSql),
$parentColumn => $connection->raw($parentSql)
);
if ( $this->node->timestamps )
$updateConditions[$this->node->getUpdatedAtColumn()] = $this->node->freshTimestamp();
return $this->node
->newNestedSetQuery()
->where(function($query) use ($leftColumn, $rightColumn, $a, $d) {
$query->whereBetween($leftColumn, array($a, $d))
->orWhereBetween($rightColumn, array($a, $d));
})
->update($updateConditions);
} | php | {
"resource": ""
} |
q242340 | Move.resolveNode | validation | protected function resolveNode($node) {
if ( $node instanceof \Baum\Node ) return $node->reload();
return $this->node->newNestedSetQuery()->find($node);
} | php | {
"resource": ""
} |
q242341 | Move.guardAgainstImpossibleMove | validation | protected function guardAgainstImpossibleMove() {
if ( !$this->node->exists )
throw new MoveNotPossibleException('A new node cannot be moved.');
if ( array_search($this->position, array('child', 'left', 'right', 'root')) === FALSE )
throw new MoveNotPossibleException("Position should be one of ['child', 'left', 'right'] but is {$this->position}.");
if ( !$this->promotingToRoot() ) {
if ( is_null($this->target) ) {
if ( $this->position === 'left' || $this->position === 'right' )
throw new MoveNotPossibleException("Could not resolve target node. This node cannot move any further to the {$this->position}.");
else
throw new MoveNotPossibleException('Could not resolve target node.');
}
if ( $this->node->equals($this->target) )
throw new MoveNotPossibleException('A node cannot be moved to itself.');
if ( $this->target->insideSubtree($this->node) )
throw new MoveNotPossibleException('A node cannot be moved to a descendant of itself (inside moved tree).');
if ( !$this->node->inSameScope($this->target) )
throw new MoveNotPossibleException('A node cannot be moved to a different scope.');
}
} | php | {
"resource": ""
} |
q242342 | Move.parentId | validation | protected function parentId() {
switch( $this->position ) {
case 'root':
return NULL;
case 'child':
return $this->target->getKey();
default:
return $this->target->getParentId();
}
} | php | {
"resource": ""
} |
q242343 | Move.hasChange | validation | protected function hasChange() {
return !( $this->bound1() == $this->node->getRight() || $this->bound1() == $this->node->getLeft() );
} | php | {
"resource": ""
} |
q242344 | Move.fireMoveEvent | validation | protected function fireMoveEvent($event, $halt = true) {
if ( !isset(static::$dispatcher) ) return true;
// Basically the same as \Illuminate\Database\Eloquent\Model->fireModelEvent
// but we relay the event into the node instance.
$event = "eloquent.{$event}: ".get_class($this->node);
$method = $halt ? 'until' : 'fire';
return static::$dispatcher->$method($event, $this->node);
} | php | {
"resource": ""
} |
q242345 | Move.quoteIdentifier | validation | protected function quoteIdentifier($value) {
if ( is_null($value) )
return 'NULL';
$connection = $this->node->getConnection();
$pdo = $connection->getPdo();
return $pdo->quote($value);
} | php | {
"resource": ""
} |
q242346 | Move.applyLockBetween | validation | protected function applyLockBetween($lft, $rgt) {
$this->node->newQuery()
->where($this->node->getLeftColumnName(), '>=', $lft)
->where($this->node->getRightColumnName(), '<=', $rgt)
->select($this->node->getKeyName())
->lockForUpdate()
->get();
} | php | {
"resource": ""
} |
q242347 | InstallCommand.writeMigration | validation | protected function writeMigration($name) {
$output = pathinfo($this->migrator->create($name, $this->getMigrationsPath()), PATHINFO_FILENAME);
$this->line(" <fg=green;options=bold>create</fg=green;options=bold> $output");
} | php | {
"resource": ""
} |
q242348 | InstallCommand.writeModel | validation | protected function writeModel($name) {
$output = pathinfo($this->modeler->create($name, $this->getModelsPath()), PATHINFO_FILENAME);
$this->line(" <fg=green;options=bold>create</fg=green;options=bold> $output");
} | php | {
"resource": ""
} |
q242349 | SetValidator.validateDuplicates | validation | protected function validateDuplicates() {
return (
!$this->duplicatesExistForColumn($this->node->getQualifiedLeftColumnName()) &&
!$this->duplicatesExistForColumn($this->node->getQualifiedRightColumnName())
);
} | php | {
"resource": ""
} |
q242350 | SetValidator.groupRootsByScope | validation | protected function groupRootsByScope($roots) {
$rootsGroupedByScope = array();
foreach($roots as $root) {
$key = $this->keyForScope($root);
if ( !isset($rootsGroupedByScope[$key]) )
$rootsGroupedByScope[$key] = array();
$rootsGroupedByScope[$key][] = $root;
}
return $rootsGroupedByScope;
} | php | {
"resource": ""
} |
q242351 | SetValidator.keyForScope | validation | protected function keyForScope($node) {
return implode('-', array_map(function($column) use ($node) {
$value = $node->getAttribute($column);
if ( is_null($value) )
return 'NULL';
return $value;
}, $node->getScopedColumns()));
} | php | {
"resource": ""
} |
q242352 | SetMapper.map | validation | public function map($nodeList) {
$self = $this;
return $this->wrapInTransaction(function() use ($self, $nodeList) {
forward_static_call(array(get_class($self->node), 'unguard'));
$result = $self->mapTree($nodeList);
forward_static_call(array(get_class($self->node), 'reguard'));
return $result;
});
} | php | {
"resource": ""
} |
q242353 | SetMapper.mapTree | validation | public function mapTree($nodeList) {
$tree = $nodeList instanceof ArrayableInterface ? $nodeList->toArray() : $nodeList;
$affectedKeys = array();
$result = $this->mapTreeRecursive($tree, $this->node->getKey(), $affectedKeys);
if ( $result && count($affectedKeys) > 0 )
$this->deleteUnaffected($affectedKeys);
return $result;
} | php | {
"resource": ""
} |
q242354 | SetMapper.mapTreeRecursive | validation | protected function mapTreeRecursive(array $tree, $parentKey = null, &$affectedKeys = array()) {
// For every attribute entry: We'll need to instantiate a new node either
// from the database (if the primary key was supplied) or a new instance. Then,
// append all the remaining data attributes (including the `parent_id` if
// present) and save it. Finally, tail-recurse performing the same
// operations for any child node present. Setting the `parent_id` property at
// each level will take care of the nesting work for us.
foreach($tree as $attributes) {
$node = $this->firstOrNew($this->getSearchAttributes($attributes));
$data = $this->getDataAttributes($attributes);
if ( !is_null($parentKey) )
$data[$node->getParentColumnName()] = $parentKey;
$node->fill($data);
$result = $node->save();
if ( ! $result ) return false;
$affectedKeys[] = $node->getKey();
if ( array_key_exists($this->getChildrenKeyName(), $attributes) ) {
$children = $attributes[$this->getChildrenKeyName()];
if ( count($children) > 0 ) {
$result = $this->mapTreeRecursive($children, $node->getKey(), $affectedKeys);
if ( ! $result ) return false;
}
}
}
return true;
} | php | {
"resource": ""
} |
q242355 | Node.boot | validation | protected static function boot() {
parent::boot();
static::creating(function($node) {
$node->setDefaultLeftAndRight();
});
static::saving(function($node) {
$node->storeNewParent();
});
static::saved(function($node) {
$node->moveToNewParent();
$node->setDepth();
});
static::deleting(function($node) {
$node->destroyDescendants();
});
if ( static::softDeletesEnabled() ) {
static::restoring(function($node) {
$node->shiftSiblingsForRestore();
});
static::restored(function($node) {
$node->restoreDescendants();
});
}
} | php | {
"resource": ""
} |
q242356 | Node.getQualifiedScopedColumns | validation | public function getQualifiedScopedColumns() {
if ( !$this->isScoped() )
return $this->getScopedColumns();
$prefix = $this->getTable() . '.';
return array_map(function($c) use ($prefix) {
return $prefix . $c; }, $this->getScopedColumns());
} | php | {
"resource": ""
} |
q242357 | Node.newNestedSetQuery | validation | public function newNestedSetQuery($excludeDeleted = true) {
$builder = $this->newQuery($excludeDeleted)->orderBy($this->getQualifiedOrderColumnName());
if ( $this->isScoped() ) {
foreach($this->scoped as $scopeFld)
$builder->where($scopeFld, '=', $this->$scopeFld);
}
return $builder;
} | php | {
"resource": ""
} |
q242358 | Node.roots | validation | public static function roots() {
$instance = new static;
return $instance->newQuery()
->whereNull($instance->getParentColumnName())
->orderBy($instance->getQualifiedOrderColumnName());
} | php | {
"resource": ""
} |
q242359 | Node.allLeaves | validation | public static function allLeaves() {
$instance = new static;
$grammar = $instance->getConnection()->getQueryGrammar();
$rgtCol = $grammar->wrap($instance->getQualifiedRightColumnName());
$lftCol = $grammar->wrap($instance->getQualifiedLeftColumnName());
return $instance->newQuery()
->whereRaw($rgtCol . ' - ' . $lftCol . ' = 1')
->orderBy($instance->getQualifiedOrderColumnName());
} | php | {
"resource": ""
} |
q242360 | Node.scopeLimitDepth | validation | public function scopeLimitDepth($query, $limit) {
$depth = $this->exists ? $this->getDepth() : $this->getLevel();
$max = $depth + $limit;
$scopes = array($depth, $max);
return $query->whereBetween($this->getDepthColumnName(), array(min($scopes), max($scopes)));
} | php | {
"resource": ""
} |
q242361 | Node.getRoot | validation | public function getRoot() {
if ( $this->exists ) {
return $this->ancestorsAndSelf()->whereNull($this->getParentColumnName())->first();
} else {
$parentId = $this->getParentId();
if ( !is_null($parentId) && $currentParent = static::find($parentId) ) {
return $currentParent->getRoot();
} else {
return $this;
}
}
} | php | {
"resource": ""
} |
q242362 | Node.ancestorsAndSelf | validation | public function ancestorsAndSelf() {
return $this->newNestedSetQuery()
->where($this->getLeftColumnName(), '<=', $this->getLeft())
->where($this->getRightColumnName(), '>=', $this->getRight());
} | php | {
"resource": ""
} |
q242363 | Node.leaves | validation | public function leaves() {
$grammar = $this->getConnection()->getQueryGrammar();
$rgtCol = $grammar->wrap($this->getQualifiedRightColumnName());
$lftCol = $grammar->wrap($this->getQualifiedLeftColumnName());
return $this->descendants()
->whereRaw($rgtCol . ' - ' . $lftCol . ' = 1');
} | php | {
"resource": ""
} |
q242364 | Node.descendantsAndSelf | validation | public function descendantsAndSelf() {
return $this->newNestedSetQuery()
->where($this->getLeftColumnName(), '>=', $this->getLeft())
->where($this->getLeftColumnName(), '<', $this->getRight());
} | php | {
"resource": ""
} |
q242365 | Node.getDescendants | validation | public function getDescendants($columns = array('*')) {
if ( is_array($columns) )
return $this->descendants()->get($columns);
$arguments = func_get_args();
$limit = intval(array_shift($arguments));
$columns = array_shift($arguments) ?: array('*');
return $this->descendants()->limitDepth($limit)->get($columns);
} | php | {
"resource": ""
} |
q242366 | Node.isDescendantOf | validation | public function isDescendantOf($other) {
return (
$this->getLeft() > $other->getLeft() &&
$this->getLeft() < $other->getRight() &&
$this->inSameScope($other)
);
} | php | {
"resource": ""
} |
q242367 | Node.isSelfOrDescendantOf | validation | public function isSelfOrDescendantOf($other) {
return (
$this->getLeft() >= $other->getLeft() &&
$this->getLeft() < $other->getRight() &&
$this->inSameScope($other)
);
} | php | {
"resource": ""
} |
q242368 | Node.isAncestorOf | validation | public function isAncestorOf($other) {
return (
$this->getLeft() < $other->getLeft() &&
$this->getRight() > $other->getLeft() &&
$this->inSameScope($other)
);
} | php | {
"resource": ""
} |
q242369 | Node.isSelfOrAncestorOf | validation | public function isSelfOrAncestorOf($other) {
return (
$this->getLeft() <= $other->getLeft() &&
$this->getRight() > $other->getLeft() &&
$this->inSameScope($other)
);
} | php | {
"resource": ""
} |
q242370 | Node.getLeftSibling | validation | public function getLeftSibling() {
return $this->siblings()
->where($this->getLeftColumnName(), '<', $this->getLeft())
->orderBy($this->getOrderColumnName(), 'desc')
->get()
->last();
} | php | {
"resource": ""
} |
q242371 | Node.makeFirstChildOf | validation | public function makeFirstChildOf($node) {
if ( $node->children()->count() == 0 )
return $this->makeChildOf($node);
return $this->moveToLeftOf($node->children()->first());
} | php | {
"resource": ""
} |
q242372 | Node.inSameScope | validation | public function inSameScope($other) {
foreach($this->getScopedColumns() as $fld) {
if ( $this->$fld != $other->$fld ) return false;
}
return true;
} | php | {
"resource": ""
} |
q242373 | Node.insideSubtree | validation | public function insideSubtree($node) {
return (
$this->getLeft() >= $node->getLeft() &&
$this->getLeft() <= $node->getRight() &&
$this->getRight() >= $node->getLeft() &&
$this->getRight() <= $node->getRight()
);
} | php | {
"resource": ""
} |
q242374 | Node.setDefaultLeftAndRight | validation | public function setDefaultLeftAndRight() {
$withHighestRight = $this->newNestedSetQuery()->reOrderBy($this->getRightColumnName(), 'desc')->take(1)->sharedLock()->first();
$maxRgt = 0;
if ( !is_null($withHighestRight) ) $maxRgt = $withHighestRight->getRight();
$this->setAttribute($this->getLeftColumnName() , $maxRgt + 1);
$this->setAttribute($this->getRightColumnName() , $maxRgt + 2);
} | php | {
"resource": ""
} |
q242375 | Node.storeNewParent | validation | public function storeNewParent() {
if ( $this->isDirty($this->getParentColumnName()) && ($this->exists || !$this->isRoot()) )
static::$moveToNewParentId = $this->getParentId();
else
static::$moveToNewParentId = FALSE;
} | php | {
"resource": ""
} |
q242376 | Node.moveToNewParent | validation | public function moveToNewParent() {
$pid = static::$moveToNewParentId;
if ( is_null($pid) )
$this->makeRoot();
else if ( $pid !== FALSE )
$this->makeChildOf($pid);
} | php | {
"resource": ""
} |
q242377 | Node.setDepth | validation | public function setDepth() {
$self = $this;
$this->getConnection()->transaction(function() use ($self) {
$self->reload();
$level = $self->getLevel();
$self->newNestedSetQuery()->where($self->getKeyName(), '=', $self->getKey())->update(array($self->getDepthColumnName() => $level));
$self->setAttribute($self->getDepthColumnName(), $level);
});
return $this;
} | php | {
"resource": ""
} |
q242378 | Node.setDepthWithSubtree | validation | public function setDepthWithSubtree() {
$self = $this;
$this->getConnection()->transaction(function() use ($self) {
$self->reload();
$self->descendantsAndSelf()->select($self->getKeyName())->lockForUpdate()->get();
$oldDepth = !is_null($self->getDepth()) ? $self->getDepth() : 0;
$newDepth = $self->getLevel();
$self->newNestedSetQuery()->where($self->getKeyName(), '=', $self->getKey())->update(array($self->getDepthColumnName() => $newDepth));
$self->setAttribute($self->getDepthColumnName(), $newDepth);
$diff = $newDepth - $oldDepth;
if ( !$self->isLeaf() && $diff != 0 )
$self->descendants()->increment($self->getDepthColumnName(), $diff);
});
return $this;
} | php | {
"resource": ""
} |
q242379 | Node.destroyDescendants | validation | public function destroyDescendants() {
if ( is_null($this->getRight()) || is_null($this->getLeft()) ) return;
$self = $this;
$this->getConnection()->transaction(function() use ($self) {
$self->reload();
$lftCol = $self->getLeftColumnName();
$rgtCol = $self->getRightColumnName();
$lft = $self->getLeft();
$rgt = $self->getRight();
// Apply a lock to the rows which fall past the deletion point
$self->newNestedSetQuery()->where($lftCol, '>=', $lft)->select($self->getKeyName())->lockForUpdate()->get();
// Prune children
$self->newNestedSetQuery()->where($lftCol, '>', $lft)->where($rgtCol, '<', $rgt)->delete();
// Update left and right indexes for the remaining nodes
$diff = $rgt - $lft + 1;
$self->newNestedSetQuery()->where($lftCol, '>', $rgt)->decrement($lftCol, $diff);
$self->newNestedSetQuery()->where($rgtCol, '>', $rgt)->decrement($rgtCol, $diff);
});
} | php | {
"resource": ""
} |
q242380 | Node.shiftSiblingsForRestore | validation | public function shiftSiblingsForRestore() {
if ( is_null($this->getRight()) || is_null($this->getLeft()) ) return;
$self = $this;
$this->getConnection()->transaction(function() use ($self) {
$lftCol = $self->getLeftColumnName();
$rgtCol = $self->getRightColumnName();
$lft = $self->getLeft();
$rgt = $self->getRight();
$diff = $rgt - $lft + 1;
$self->newNestedSetQuery()->where($lftCol, '>=', $lft)->increment($lftCol, $diff);
$self->newNestedSetQuery()->where($rgtCol, '>=', $lft)->increment($rgtCol, $diff);
});
} | php | {
"resource": ""
} |
q242381 | Node.computeLevel | validation | protected function computeLevel() {
list($node, $nesting) = $this->determineDepth($this);
if ( $node->equals($this) )
return $this->ancestors()->count();
return $node->getLevel() + $nesting;
} | php | {
"resource": ""
} |
q242382 | ChoiceFormField.setValue | validation | public function setValue($value)
{
if (\is_bool($value)) {
if ('checkbox' !== $this->type) {
throw new \InvalidArgumentException(\sprintf('Invalid argument of type "%s"', \gettype($value)));
}
if ($value) {
if (!$this->element->isSelected()) {
$this->element->click();
}
} elseif ($this->element->isSelected()) {
$this->element->click();
}
return;
}
foreach ((array) $value as $v) {
$this->selector->selectByValue($v);
}
} | php | {
"resource": ""
} |
q242383 | ChoiceFormField.availableOptionValues | validation | public function availableOptionValues()
{
$options = [];
foreach ($this->selector->getOptions() as $option) {
$options[] = $option->getAttribute('value');
}
return $options;
} | php | {
"resource": ""
} |
q242384 | JsValidationServiceProvider.bootstrapViews | validation | protected function bootstrapViews()
{
$viewPath = realpath(__DIR__.'/../resources/views');
$this->loadViewsFrom($viewPath, 'jsvalidation');
$this->publishes([
$viewPath => $this->app['path.base'].'/resources/views/vendor/jsvalidation',
], 'views');
} | php | {
"resource": ""
} |
q242385 | JsValidationServiceProvider.bootstrapConfigs | validation | protected function bootstrapConfigs()
{
$configFile = realpath(__DIR__.'/../config/jsvalidation.php');
$this->mergeConfigFrom($configFile, 'jsvalidation');
$this->publishes([$configFile => $this->app['path.config'].'/jsvalidation.php'], 'config');
} | php | {
"resource": ""
} |
q242386 | RuleParser.getRule | validation | public function getRule($attribute, $rule, $parameters, $rawRule)
{
$isConditional = $this->isConditionalRule($attribute, $rawRule);
$isRemote = $this->isRemoteRule($rule);
if ($isConditional || $isRemote) {
list($attribute, $parameters) = $this->remoteRule($attribute, $isConditional);
$jsRule = self::REMOTE_RULE;
} else {
list($jsRule, $attribute, $parameters) = $this->clientRule($attribute, $rule, $parameters);
}
$attribute = $this->getAttributeName($attribute);
return [$attribute, $jsRule, $parameters];
} | php | {
"resource": ""
} |
q242387 | RuleParser.addConditionalRules | validation | public function addConditionalRules($attribute, $rules = [])
{
foreach ((array) $attribute as $key) {
$current = isset($this->conditional[$key]) ? $this->conditional[$key] : [];
$merge = head($this->validator->explodeRules((array) $rules));
$this->conditional[$key] = array_merge($current, $merge);
}
} | php | {
"resource": ""
} |
q242388 | RuleParser.isConditionalRule | validation | protected function isConditionalRule($attribute, $rule)
{
return isset($this->conditional[$attribute]) &&
in_array($rule, $this->conditional[$attribute]);
} | php | {
"resource": ""
} |
q242389 | RuleParser.getAttributeName | validation | protected function getAttributeName($attribute)
{
$attributeArray = explode('.', $attribute);
if (count($attributeArray) > 1) {
return $attributeArray[0].'['.implode('][', array_slice($attributeArray, 1)).']';
}
return $attribute;
} | php | {
"resource": ""
} |
q242390 | JavascriptValidator.setDefaults | validation | protected function setDefaults($options)
{
$this->selector = empty($options['selector']) ? 'form' : $options['selector'];
$this->view = empty($options['view']) ? 'jsvalidation::bootstrap' : $options['view'];
$this->remote = isset($options['remote']) ? $options['remote'] : true;
} | php | {
"resource": ""
} |
q242391 | JavascriptValidator.render | validation | public function render($view = null, $selector = null)
{
$this->view($view);
$this->selector($selector);
return View::make($this->view, ['validator' => $this->getViewData()])
->render();
} | php | {
"resource": ""
} |
q242392 | JavascriptValidator.getViewData | validation | protected function getViewData()
{
$this->validator->setRemote($this->remote);
$data = $this->validator->validationData();
$data['selector'] = $this->selector;
if (! is_null($this->ignore)) {
$data['ignore'] = $this->ignore;
}
return $data;
} | php | {
"resource": ""
} |
q242393 | JavascriptValidator.selector | validation | public function selector($selector)
{
$this->selector = is_null($selector) ? $this->selector : $selector;
return $this;
} | php | {
"resource": ""
} |
q242394 | JavascriptValidator.view | validation | public function view($view)
{
$this->view = is_null($view) ? $this->view : $view;
return $this;
} | php | {
"resource": ""
} |
q242395 | DelegatedValidator.makeReplacements | validation | public function makeReplacements($message, $attribute, $rule, $parameters)
{
if (is_object($rule)) {
$rule = get_class($rule);
}
return $this->callValidator('makeReplacements', [$message, $attribute, $rule, $parameters]);
} | php | {
"resource": ""
} |
q242396 | DelegatedValidator.getMessage | validation | public function getMessage($attribute, $rule)
{
if (is_object($rule)) {
$rule = get_class($rule);
}
return $this->callValidator('getMessage', [$attribute, $rule]);
} | php | {
"resource": ""
} |
q242397 | DelegatedValidator.sometimes | validation | public function sometimes($attribute, $rules, callable $callback)
{
$this->validator->sometimes($attribute, $rules, $callback);
} | php | {
"resource": ""
} |
q242398 | JavascriptRulesTrait.ruleConfirmed | validation | protected function ruleConfirmed($attribute, array $parameters)
{
$parameters[0] = $this->getAttributeName($attribute);
$attribute = "{$attribute}_confirmation";
return [$attribute, $parameters];
} | php | {
"resource": ""
} |
q242399 | JavascriptRulesTrait.ruleAfter | validation | protected function ruleAfter($attribute, array $parameters)
{
if (! ($date = strtotime($parameters[0]))) {
$date = $this->getAttributeName($parameters[0]);
}
return [$attribute, [$date]];
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.