repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
eloquent/phony
src/Stub/Answer/CallRequest.php
CallRequest.finalArguments
public function finalArguments($self, Arguments $arguments): Arguments { $finalArguments = $this->arguments->all(); if ($this->prefixSelf) { array_unshift($finalArguments, $self); } if ($this->suffixArgumentsObject) { $finalArguments[] = $arguments; } if ($this->suffixArguments && $arguments) { $finalArguments = array_merge($finalArguments, $arguments->all()); } return new Arguments($finalArguments); }
php
public function finalArguments($self, Arguments $arguments): Arguments { $finalArguments = $this->arguments->all(); if ($this->prefixSelf) { array_unshift($finalArguments, $self); } if ($this->suffixArgumentsObject) { $finalArguments[] = $arguments; } if ($this->suffixArguments && $arguments) { $finalArguments = array_merge($finalArguments, $arguments->all()); } return new Arguments($finalArguments); }
[ "public", "function", "finalArguments", "(", "$", "self", ",", "Arguments", "$", "arguments", ")", ":", "Arguments", "{", "$", "finalArguments", "=", "$", "this", "->", "arguments", "->", "all", "(", ")", ";", "if", "(", "$", "this", "->", "prefixSelf", ...
Get the final arguments. @param object $self The self value. @param Arguments $arguments The incoming arguments. @return Arguments The final arguments.
[ "Get", "the", "final", "arguments", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/CallRequest.php#L62-L78
train
eloquent/phony
src/Stub/Answer/Builder/GeneratorAnswerBuilderFactory.php
GeneratorAnswerBuilderFactory.create
public function create(Stub $stub): GeneratorAnswerBuilder { return new GeneratorAnswerBuilder( $stub, $this->invocableInspector, $this->invoker ); }
php
public function create(Stub $stub): GeneratorAnswerBuilder { return new GeneratorAnswerBuilder( $stub, $this->invocableInspector, $this->invoker ); }
[ "public", "function", "create", "(", "Stub", "$", "stub", ")", ":", "GeneratorAnswerBuilder", "{", "return", "new", "GeneratorAnswerBuilder", "(", "$", "stub", ",", "$", "this", "->", "invocableInspector", ",", "$", "this", "->", "invoker", ")", ";", "}" ]
Create a generator answer builder for the supplied stub. @param Stub $stub The stub. @return GeneratorAnswerBuilder The newly created builder.
[ "Create", "a", "generator", "answer", "builder", "for", "the", "supplied", "stub", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilderFactory.php#L54-L61
train
eloquent/phony
src/Call/CallVerifierFactory.php
CallVerifierFactory.fromCall
public function fromCall(Call $call): CallVerifier { return new CallVerifier( $call, $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->assertionRecorder, $this->assertionRenderer ); }
php
public function fromCall(Call $call): CallVerifier { return new CallVerifier( $call, $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->assertionRecorder, $this->assertionRenderer ); }
[ "public", "function", "fromCall", "(", "Call", "$", "call", ")", ":", "CallVerifier", "{", "return", "new", "CallVerifier", "(", "$", "call", ",", "$", "this", "->", "matcherFactory", ",", "$", "this", "->", "matcherVerifier", ",", "$", "this", "->", "ge...
Wrap the supplied call in a verifier. @param Call $call The call. @return CallVerifier The call verifier.
[ "Wrap", "the", "supplied", "call", "in", "a", "verifier", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifierFactory.php#L74-L85
train
eloquent/phony
src/Call/CallVerifierFactory.php
CallVerifierFactory.fromCalls
public function fromCalls(array $calls): array { $verifiers = []; foreach ($calls as $call) { $verifiers[] = new CallVerifier( $call, $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->assertionRecorder, $this->assertionRenderer ); } return $verifiers; }
php
public function fromCalls(array $calls): array { $verifiers = []; foreach ($calls as $call) { $verifiers[] = new CallVerifier( $call, $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->assertionRecorder, $this->assertionRenderer ); } return $verifiers; }
[ "public", "function", "fromCalls", "(", "array", "$", "calls", ")", ":", "array", "{", "$", "verifiers", "=", "[", "]", ";", "foreach", "(", "$", "calls", "as", "$", "call", ")", "{", "$", "verifiers", "[", "]", "=", "new", "CallVerifier", "(", "$"...
Wrap the supplied calls in verifiers. @param array<Call> $calls The calls. @return array<CallVerifier> The call verifiers.
[ "Wrap", "the", "supplied", "calls", "in", "verifiers", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifierFactory.php#L94-L111
train
eloquent/phony
src/Invocation/Invoker.php
Invoker.callWith
public function callWith($callback, Arguments $arguments) { if ($callback instanceof Invocable) { return $callback->invokeWith($arguments); } $arguments = $arguments->all(); return $callback(...$arguments); }
php
public function callWith($callback, Arguments $arguments) { if ($callback instanceof Invocable) { return $callback->invokeWith($arguments); } $arguments = $arguments->all(); return $callback(...$arguments); }
[ "public", "function", "callWith", "(", "$", "callback", ",", "Arguments", "$", "arguments", ")", "{", "if", "(", "$", "callback", "instanceof", "Invocable", ")", "{", "return", "$", "callback", "->", "invokeWith", "(", "$", "arguments", ")", ";", "}", "$...
Calls a callback, maintaining reference parameters. @param callable $callback The callback. @param Arguments $arguments The arguments. @return mixed The result of invocation. @throws Throwable If an error occurs.
[ "Calls", "a", "callback", "maintaining", "reference", "parameters", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Invocation/Invoker.php#L38-L47
train
eloquent/phony
src/Call/CallData.php
CallData.compareSequential
public static function compareSequential(Call $a, Call $b): int { return $a->sequenceNumber() <=> $b->sequenceNumber(); }
php
public static function compareSequential(Call $a, Call $b): int { return $a->sequenceNumber() <=> $b->sequenceNumber(); }
[ "public", "static", "function", "compareSequential", "(", "Call", "$", "a", ",", "Call", "$", "b", ")", ":", "int", "{", "return", "$", "a", "->", "sequenceNumber", "(", ")", "<=>", "$", "b", "->", "sequenceNumber", "(", ")", ";", "}" ]
A comparator for ordering calls by sequence number. @param Call $a The first call. @param Call $b The second call. @return int The comparison value.
[ "A", "comparator", "for", "ordering", "calls", "by", "sequence", "number", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L37-L40
train
eloquent/phony
src/Call/CallData.php
CallData.setResponseEvent
public function setResponseEvent(ResponseEvent $responseEvent): void { if ($this->responseEvent) { throw new InvalidArgumentException('Call already responded.'); } $responseEvent->setCall($this); $this->responseEvent = $responseEvent; }
php
public function setResponseEvent(ResponseEvent $responseEvent): void { if ($this->responseEvent) { throw new InvalidArgumentException('Call already responded.'); } $responseEvent->setCall($this); $this->responseEvent = $responseEvent; }
[ "public", "function", "setResponseEvent", "(", "ResponseEvent", "$", "responseEvent", ")", ":", "void", "{", "if", "(", "$", "this", "->", "responseEvent", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Call already responded.'", ")", ";", "}", "$"...
Set the response event. @param ResponseEvent $responseEvent The response event. @throws InvalidArgumentException If the call has already responded.
[ "Set", "the", "response", "event", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L281-L289
train
eloquent/phony
src/Call/CallData.php
CallData.addIterableEvent
public function addIterableEvent(IterableEvent $iterableEvent): void { if (!$this->isIterable()) { throw new InvalidArgumentException('Not an iterable call.'); } if ($this->endEvent) { throw new InvalidArgumentException('Call already completed.'); } $iterableEvent->setCall($this); $this->iterableEvents[] = $iterableEvent; }
php
public function addIterableEvent(IterableEvent $iterableEvent): void { if (!$this->isIterable()) { throw new InvalidArgumentException('Not an iterable call.'); } if ($this->endEvent) { throw new InvalidArgumentException('Call already completed.'); } $iterableEvent->setCall($this); $this->iterableEvents[] = $iterableEvent; }
[ "public", "function", "addIterableEvent", "(", "IterableEvent", "$", "iterableEvent", ")", ":", "void", "{", "if", "(", "!", "$", "this", "->", "isIterable", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Not an iterable call.'", ")", "...
Add an iterable event. @param IterableEvent $iterableEvent The iterable event. @throws InvalidArgumentException If the call has already completed.
[ "Add", "an", "iterable", "event", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L308-L319
train
eloquent/phony
src/Call/CallData.php
CallData.setEndEvent
public function setEndEvent(EndEvent $endEvent): void { if ($this->endEvent) { throw new InvalidArgumentException('Call already completed.'); } $endEvent->setCall($this); if (!$this->responseEvent) { $this->responseEvent = $endEvent; } $this->endEvent = $endEvent; }
php
public function setEndEvent(EndEvent $endEvent): void { if ($this->endEvent) { throw new InvalidArgumentException('Call already completed.'); } $endEvent->setCall($this); if (!$this->responseEvent) { $this->responseEvent = $endEvent; } $this->endEvent = $endEvent; }
[ "public", "function", "setEndEvent", "(", "EndEvent", "$", "endEvent", ")", ":", "void", "{", "if", "(", "$", "this", "->", "endEvent", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Call already completed.'", ")", ";", "}", "$", "endEvent", "-...
Set the end event. @param EndEvent $endEvent The end event. @throws InvalidArgumentException If the call has already completed.
[ "Set", "the", "end", "event", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L338-L351
train
eloquent/phony
src/Call/CallData.php
CallData.allEvents
public function allEvents(): array { $events = $this->iterableEvents(); if ($this->endEvent && $this->responseEvent !== $this->endEvent) { $events[] = $this->endEvent; } if ($this->responseEvent) { array_unshift($events, $this->responseEvent); } array_unshift($events, $this->calledEvent); return $events; }
php
public function allEvents(): array { $events = $this->iterableEvents(); if ($this->endEvent && $this->responseEvent !== $this->endEvent) { $events[] = $this->endEvent; } if ($this->responseEvent) { array_unshift($events, $this->responseEvent); } array_unshift($events, $this->calledEvent); return $events; }
[ "public", "function", "allEvents", "(", ")", ":", "array", "{", "$", "events", "=", "$", "this", "->", "iterableEvents", "(", ")", ";", "if", "(", "$", "this", "->", "endEvent", "&&", "$", "this", "->", "responseEvent", "!==", "$", "this", "->", "end...
Get all events as an array. @return array<Event> The events.
[ "Get", "all", "events", "as", "an", "array", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L368-L383
train
eloquent/phony
src/Call/CallData.php
CallData.isIterable
public function isIterable(): bool { if (!$this->responseEvent instanceof ReturnedEvent) { return false; } $returnValue = $this->responseEvent->value(); return is_array($returnValue) || $returnValue instanceof Traversable; }
php
public function isIterable(): bool { if (!$this->responseEvent instanceof ReturnedEvent) { return false; } $returnValue = $this->responseEvent->value(); return is_array($returnValue) || $returnValue instanceof Traversable; }
[ "public", "function", "isIterable", "(", ")", ":", "bool", "{", "if", "(", "!", "$", "this", "->", "responseEvent", "instanceof", "ReturnedEvent", ")", "{", "return", "false", ";", "}", "$", "returnValue", "=", "$", "this", "->", "responseEvent", "->", "...
Returns true if this call has responded with an iterable. @return bool True if this call has responded with an iterable.
[ "Returns", "true", "if", "this", "call", "has", "responded", "with", "an", "iterable", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L412-L421
train
eloquent/phony
src/Call/CallData.php
CallData.generatorResponse
public function generatorResponse(): array { if ($this->endEvent instanceof ReturnedEvent) { return [null, $this->endEvent->value()]; } if ($this->endEvent instanceof ThrewEvent) { return [$this->endEvent->exception(), null]; } throw new UndefinedResponseException( 'The call has not yet responded via generator.' ); }
php
public function generatorResponse(): array { if ($this->endEvent instanceof ReturnedEvent) { return [null, $this->endEvent->value()]; } if ($this->endEvent instanceof ThrewEvent) { return [$this->endEvent->exception(), null]; } throw new UndefinedResponseException( 'The call has not yet responded via generator.' ); }
[ "public", "function", "generatorResponse", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "endEvent", "instanceof", "ReturnedEvent", ")", "{", "return", "[", "null", ",", "$", "this", "->", "endEvent", "->", "value", "(", ")", "]", ";", "}"...
Get the response from the generator. @return tuple<Throwable|null,mixed> A 2-tuple of thrown exception or null, and return value. @throws UndefinedResponseException If this call has not yet responded via generator.
[ "Get", "the", "response", "from", "the", "generator", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L581-L594
train
eloquent/phony
src/Mock/Builder/Method/MethodDefinitionCollection.php
MethodDefinitionCollection.methodName
public function methodName(string $name): string { $name = strtolower($name); return $this->methodNames[$name] ?? ''; }
php
public function methodName(string $name): string { $name = strtolower($name); return $this->methodNames[$name] ?? ''; }
[ "public", "function", "methodName", "(", "string", "$", "name", ")", ":", "string", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "return", "$", "this", "->", "methodNames", "[", "$", "name", "]", "??", "''", ";", "}" ]
Get the canonical method name for the supplied method name. @param string $name The method name. @return string The canonical method name, or an empty string if no such method exists.
[ "Get", "the", "canonical", "method", "name", "for", "the", "supplied", "method", "name", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/Method/MethodDefinitionCollection.php#L66-L71
train
eloquent/phony
src/Mock/Handle/HandleFactory.php
HandleFactory.staticHandle
public function staticHandle($class): StaticHandle { if ($class instanceof StaticHandle) { return $class; } if ($class instanceof Handle) { $class = $class->class(); } elseif ($class instanceof Mock) { $class = new ReflectionClass($class); } elseif (is_string($class)) { try { $class = new ReflectionClass($class); } catch (ReflectionException $e) { throw new NonMockClassException($class, $e); } } elseif (!$class instanceof ReflectionClass) { throw new InvalidMockClassException($class); } if (!$class->isSubclassOf(Mock::class)) { throw new NonMockClassException($class->getName()); } $handleProperty = $class->getProperty('_staticHandle'); $handleProperty->setAccessible(true); if ($handle = $handleProperty->getValue(null)) { return $handle; } $handle = new StaticHandle( $class, (object) [ 'defaultAnswerCallback' => [StubData::class, 'forwardsAnswerCallback'], 'stubs' => (object) [], 'isRecording' => true, ], $this->stubFactory, $this->stubVerifierFactory, $this->emptyValueFactory, $this->assertionRenderer, $this->assertionRecorder, $this->invoker ); $handleProperty->setValue(null, $handle); return $handle; }
php
public function staticHandle($class): StaticHandle { if ($class instanceof StaticHandle) { return $class; } if ($class instanceof Handle) { $class = $class->class(); } elseif ($class instanceof Mock) { $class = new ReflectionClass($class); } elseif (is_string($class)) { try { $class = new ReflectionClass($class); } catch (ReflectionException $e) { throw new NonMockClassException($class, $e); } } elseif (!$class instanceof ReflectionClass) { throw new InvalidMockClassException($class); } if (!$class->isSubclassOf(Mock::class)) { throw new NonMockClassException($class->getName()); } $handleProperty = $class->getProperty('_staticHandle'); $handleProperty->setAccessible(true); if ($handle = $handleProperty->getValue(null)) { return $handle; } $handle = new StaticHandle( $class, (object) [ 'defaultAnswerCallback' => [StubData::class, 'forwardsAnswerCallback'], 'stubs' => (object) [], 'isRecording' => true, ], $this->stubFactory, $this->stubVerifierFactory, $this->emptyValueFactory, $this->assertionRenderer, $this->assertionRecorder, $this->invoker ); $handleProperty->setValue(null, $handle); return $handle; }
[ "public", "function", "staticHandle", "(", "$", "class", ")", ":", "StaticHandle", "{", "if", "(", "$", "class", "instanceof", "StaticHandle", ")", "{", "return", "$", "class", ";", "}", "if", "(", "$", "class", "instanceof", "Handle", ")", "{", "$", "...
Create a new static handle. @param Mock|Handle|ReflectionClass|string $class The class. @return StaticHandle The newly created handle. @throws MockException If the supplied class name is not a mock class.
[ "Create", "a", "new", "static", "handle", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Handle/HandleFactory.php#L135-L185
train
eloquent/phony
src/Spy/SpyVerifier.php
SpyVerifier.checkCalled
public function checkCalled(): ?EventCollection { $cardinality = $this->resetCardinality(); $calls = $this->spy->allCalls(); $callCount = count($calls); if ($cardinality->matches($callCount, $callCount)) { return $this->assertionRecorder->createSuccess($calls); } return null; }
php
public function checkCalled(): ?EventCollection { $cardinality = $this->resetCardinality(); $calls = $this->spy->allCalls(); $callCount = count($calls); if ($cardinality->matches($callCount, $callCount)) { return $this->assertionRecorder->createSuccess($calls); } return null; }
[ "public", "function", "checkCalled", "(", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", ";", "$", "calls", "=", "$", "this", "->", "spy", "->", "allCalls", "(", ")", ";", "$", "callCoun...
Checks if called. @return EventCollection|null The result.
[ "Checks", "if", "called", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L424-L436
train
eloquent/phony
src/Spy/SpyVerifier.php
SpyVerifier.called
public function called(): ?EventCollection { $cardinality = $this->cardinality; if ($result = $this->checkCalled()) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderCalled($this->spy, $cardinality) ); }
php
public function called(): ?EventCollection { $cardinality = $this->cardinality; if ($result = $this->checkCalled()) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderCalled($this->spy, $cardinality) ); }
[ "public", "function", "called", "(", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "cardinality", ";", "if", "(", "$", "result", "=", "$", "this", "->", "checkCalled", "(", ")", ")", "{", "return", "$", "result", ...
Throws an exception unless called. @return EventCollection|null The result, or null if the assertion recorder does not throw exceptions. @throws Throwable If the assertion fails, and the assertion recorder throws exceptions.
[ "Throws", "an", "exception", "unless", "called", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L444-L455
train
eloquent/phony
src/Spy/SpyVerifier.php
SpyVerifier.responded
public function responded(): ?EventCollection { $cardinality = $this->cardinality; if ($result = $this->checkResponded()) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderResponded($this->spy, $cardinality) ); }
php
public function responded(): ?EventCollection { $cardinality = $this->cardinality; if ($result = $this->checkResponded()) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderResponded($this->spy, $cardinality) ); }
[ "public", "function", "responded", "(", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "cardinality", ";", "if", "(", "$", "result", "=", "$", "this", "->", "checkResponded", "(", ")", ")", "{", "return", "$", "resul...
Throws an exception unless this spy responded. @return EventCollection|null The result, or null if the assertion recorder does not throw exceptions. @throws Throwable If the assertion fails, and the assertion recorder throws exceptions.
[ "Throws", "an", "exception", "unless", "this", "spy", "responded", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L548-L559
train
eloquent/phony
src/Spy/SpyVerifier.php
SpyVerifier.checkCompleted
public function checkCompleted(): ?EventCollection { $cardinality = $this->resetCardinality(); $calls = $this->spy->allCalls(); $matchingEvents = []; $totalCount = count($calls); $matchCount = 0; foreach ($calls as $call) { if ($endEvent = $call->endEvent()) { $matchingEvents[] = $endEvent; ++$matchCount; } } if ($cardinality->matches($matchCount, $totalCount)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
php
public function checkCompleted(): ?EventCollection { $cardinality = $this->resetCardinality(); $calls = $this->spy->allCalls(); $matchingEvents = []; $totalCount = count($calls); $matchCount = 0; foreach ($calls as $call) { if ($endEvent = $call->endEvent()) { $matchingEvents[] = $endEvent; ++$matchCount; } } if ($cardinality->matches($matchCount, $totalCount)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
[ "public", "function", "checkCompleted", "(", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", ";", "$", "calls", "=", "$", "this", "->", "spy", "->", "allCalls", "(", ")", ";", "$", "match...
Checks if this spy completed. @return EventCollection|null The result.
[ "Checks", "if", "this", "spy", "completed", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L566-L587
train
eloquent/phony
src/Spy/SpyVerifier.php
SpyVerifier.checkReturned
public function checkReturned($value = null): ?EventCollection { $cardinality = $this->resetCardinality(); $calls = $this->spy->allCalls(); $matchingEvents = []; $totalCount = count($calls); $matchCount = 0; if (0 === func_num_args()) { foreach ($calls as $call) { if (!$responseEvent = $call->responseEvent()) { continue; } list($exception) = $call->response(); if (!$exception) { $matchingEvents[] = $responseEvent; ++$matchCount; } } } else { $value = $this->matcherFactory->adapt($value); foreach ($calls as $call) { if (!$responseEvent = $call->responseEvent()) { continue; } list($exception, $returnValue) = $call->response(); if (!$exception && $value->matches($returnValue)) { $matchingEvents[] = $responseEvent; ++$matchCount; } } } if ($cardinality->matches($matchCount, $totalCount)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
php
public function checkReturned($value = null): ?EventCollection { $cardinality = $this->resetCardinality(); $calls = $this->spy->allCalls(); $matchingEvents = []; $totalCount = count($calls); $matchCount = 0; if (0 === func_num_args()) { foreach ($calls as $call) { if (!$responseEvent = $call->responseEvent()) { continue; } list($exception) = $call->response(); if (!$exception) { $matchingEvents[] = $responseEvent; ++$matchCount; } } } else { $value = $this->matcherFactory->adapt($value); foreach ($calls as $call) { if (!$responseEvent = $call->responseEvent()) { continue; } list($exception, $returnValue) = $call->response(); if (!$exception && $value->matches($returnValue)) { $matchingEvents[] = $responseEvent; ++$matchCount; } } } if ($cardinality->matches($matchCount, $totalCount)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
[ "public", "function", "checkReturned", "(", "$", "value", "=", "null", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", ";", "$", "calls", "=", "$", "this", "->", "spy", "->", "allCalls", ...
Checks if this spy returned the supplied value. @param mixed $value The value. @return EventCollection|null The result.
[ "Checks", "if", "this", "spy", "returned", "the", "supplied", "value", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L615-L659
train
eloquent/phony
src/Spy/SpyVerifier.php
SpyVerifier.checkGenerated
public function checkGenerated(): ?GeneratorVerifier { $cardinality = $this->resetCardinality(); $calls = $this->spy->allCalls(); $matchingEvents = []; $totalCount = count($calls); $matchCount = 0; foreach ($calls as $call) { if (!$call->responseEvent()) { continue; } list(, $returnValue) = $call->response(); if ($returnValue instanceof Generator) { $matchingEvents[] = $call; ++$matchCount; } } if ($cardinality->matches($matchCount, $totalCount)) { return $this->assertionRecorder->createSuccessFromEventCollection( $this->generatorVerifierFactory ->create($this->spy, $matchingEvents) ); } return null; }
php
public function checkGenerated(): ?GeneratorVerifier { $cardinality = $this->resetCardinality(); $calls = $this->spy->allCalls(); $matchingEvents = []; $totalCount = count($calls); $matchCount = 0; foreach ($calls as $call) { if (!$call->responseEvent()) { continue; } list(, $returnValue) = $call->response(); if ($returnValue instanceof Generator) { $matchingEvents[] = $call; ++$matchCount; } } if ($cardinality->matches($matchCount, $totalCount)) { return $this->assertionRecorder->createSuccessFromEventCollection( $this->generatorVerifierFactory ->create($this->spy, $matchingEvents) ); } return null; }
[ "public", "function", "checkGenerated", "(", ")", ":", "?", "GeneratorVerifier", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", ";", "$", "calls", "=", "$", "this", "->", "spy", "->", "allCalls", "(", ")", ";", "$", "mat...
Checks if this spy returned a generator. @return GeneratorVerifier|null The result.
[ "Checks", "if", "this", "spy", "returned", "a", "generator", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L822-L852
train
eloquent/phony
src/Spy/SpyVerifier.php
SpyVerifier.generated
public function generated(): ?GeneratorVerifier { $cardinality = $this->cardinality; if ($result = $this->checkGenerated()) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderGenerated($this->spy, $cardinality) ); }
php
public function generated(): ?GeneratorVerifier { $cardinality = $this->cardinality; if ($result = $this->checkGenerated()) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderGenerated($this->spy, $cardinality) ); }
[ "public", "function", "generated", "(", ")", ":", "?", "GeneratorVerifier", "{", "$", "cardinality", "=", "$", "this", "->", "cardinality", ";", "if", "(", "$", "result", "=", "$", "this", "->", "checkGenerated", "(", ")", ")", "{", "return", "$", "res...
Throws an exception unless this spy returned a generator. @return GeneratorVerifier The result, or null if the assertion recorder does not throw exceptions. @throws Throwable If the assertion fails, and the assertion recorder throws exceptions.
[ "Throws", "an", "exception", "unless", "this", "spy", "returned", "a", "generator", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L860-L871
train
eloquent/phony
src/Spy/SpyVerifier.php
SpyVerifier.checkIterated
public function checkIterated(): ?IterableVerifier { $cardinality = $this->resetCardinality(); $calls = $this->spy->allCalls(); $matchingEvents = []; $totalCount = count($calls); $matchCount = 0; foreach ($calls as $call) { if (!$call->responseEvent()) { continue; } list(, $returnValue) = $call->response(); if ($returnValue instanceof Traversable || is_array($returnValue)) { $matchingEvents[] = $call; ++$matchCount; } } if ($cardinality->matches($matchCount, $totalCount)) { return $this->assertionRecorder->createSuccessFromEventCollection( $this->iterableVerifierFactory ->create($this->spy, $matchingEvents) ); } return null; }
php
public function checkIterated(): ?IterableVerifier { $cardinality = $this->resetCardinality(); $calls = $this->spy->allCalls(); $matchingEvents = []; $totalCount = count($calls); $matchCount = 0; foreach ($calls as $call) { if (!$call->responseEvent()) { continue; } list(, $returnValue) = $call->response(); if ($returnValue instanceof Traversable || is_array($returnValue)) { $matchingEvents[] = $call; ++$matchCount; } } if ($cardinality->matches($matchCount, $totalCount)) { return $this->assertionRecorder->createSuccessFromEventCollection( $this->iterableVerifierFactory ->create($this->spy, $matchingEvents) ); } return null; }
[ "public", "function", "checkIterated", "(", ")", ":", "?", "IterableVerifier", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", ";", "$", "calls", "=", "$", "this", "->", "spy", "->", "allCalls", "(", ")", ";", "$", "match...
Checks if this spy returned an iterable. @return IterableVerifier|null The result.
[ "Checks", "if", "this", "spy", "returned", "an", "iterable", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L878-L908
train
eloquent/phony
src/Spy/SpyVerifierFactory.php
SpyVerifierFactory.create
public function create(Spy $spy = null): SpyVerifier { if (!$spy) { $spy = $this->spyFactory->create(); } return new SpyVerifier( $spy, $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer ); }
php
public function create(Spy $spy = null): SpyVerifier { if (!$spy) { $spy = $this->spyFactory->create(); } return new SpyVerifier( $spy, $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer ); }
[ "public", "function", "create", "(", "Spy", "$", "spy", "=", "null", ")", ":", "SpyVerifier", "{", "if", "(", "!", "$", "spy", ")", "{", "$", "spy", "=", "$", "this", "->", "spyFactory", "->", "create", "(", ")", ";", "}", "return", "new", "SpyVe...
Create a new spy verifier. @param Spy|null $spy The spy, or null to create an anonymous spy. @return SpyVerifier The newly created spy verifier.
[ "Create", "a", "new", "spy", "verifier", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifierFactory.php#L89-L105
train
eloquent/phony
src/Spy/SpyVerifierFactory.php
SpyVerifierFactory.createFromCallback
public function createFromCallback($callback): SpyVerifier { return new SpyVerifier( $this->spyFactory->create($callback), $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer ); }
php
public function createFromCallback($callback): SpyVerifier { return new SpyVerifier( $this->spyFactory->create($callback), $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer ); }
[ "public", "function", "createFromCallback", "(", "$", "callback", ")", ":", "SpyVerifier", "{", "return", "new", "SpyVerifier", "(", "$", "this", "->", "spyFactory", "->", "create", "(", "$", "callback", ")", ",", "$", "this", "->", "matcherFactory", ",", ...
Create a new spy verifier for the supplied callback. @param callable|null $callback The callback, or null to create an anonymous spy. @return SpyVerifier The newly created spy verifier.
[ "Create", "a", "new", "spy", "verifier", "for", "the", "supplied", "callback", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifierFactory.php#L114-L126
train
eloquent/phony
src/Spy/SpyVerifierFactory.php
SpyVerifierFactory.createGlobal
public function createGlobal( string $function, string $namespace ): SpyVerifier { if (false !== strpos($function, '\\')) { throw new InvalidArgumentException( 'Only functions in the global namespace are supported.' ); } $namespace = trim($namespace, '\\'); if (!$namespace) { throw new InvalidArgumentException( 'The supplied namespace must not be empty.' ); } $spy = $this->spyFactory->create($function); $this->functionHookManager->defineFunction($function, $namespace, $spy); return new SpyVerifier( $spy, $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer ); }
php
public function createGlobal( string $function, string $namespace ): SpyVerifier { if (false !== strpos($function, '\\')) { throw new InvalidArgumentException( 'Only functions in the global namespace are supported.' ); } $namespace = trim($namespace, '\\'); if (!$namespace) { throw new InvalidArgumentException( 'The supplied namespace must not be empty.' ); } $spy = $this->spyFactory->create($function); $this->functionHookManager->defineFunction($function, $namespace, $spy); return new SpyVerifier( $spy, $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer ); }
[ "public", "function", "createGlobal", "(", "string", "$", "function", ",", "string", "$", "namespace", ")", ":", "SpyVerifier", "{", "if", "(", "false", "!==", "strpos", "(", "$", "function", ",", "'\\\\'", ")", ")", "{", "throw", "new", "InvalidArgumentEx...
Create a new spy verifier for a global function and declare it in the specified namespace. @param string $function The function name. @param string $namespace The namespace. @return SpyVerifier The newly created spy verifier. @throws InvalidArgumentException If an invalid function name or namespace is specified.
[ "Create", "a", "new", "spy", "verifier", "for", "a", "global", "function", "and", "declare", "it", "in", "the", "specified", "namespace", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifierFactory.php#L138-L169
train
eloquent/phony
src/Mock/Handle/InstanceHandle.php
InstanceHandle.constructWith
public function constructWith($arguments = []): self { if ($this->callParentConstructorMethod) { if (!$arguments instanceof Arguments) { $arguments = new Arguments($arguments); } $this->callParentConstructorMethod->invoke($this->mock, $arguments); } return $this; }
php
public function constructWith($arguments = []): self { if ($this->callParentConstructorMethod) { if (!$arguments instanceof Arguments) { $arguments = new Arguments($arguments); } $this->callParentConstructorMethod->invoke($this->mock, $arguments); } return $this; }
[ "public", "function", "constructWith", "(", "$", "arguments", "=", "[", "]", ")", ":", "self", "{", "if", "(", "$", "this", "->", "callParentConstructorMethod", ")", "{", "if", "(", "!", "$", "arguments", "instanceof", "Arguments", ")", "{", "$", "argume...
Call the original constructor. @param Arguments|array $arguments The arguments. @return $this This handle.
[ "Call", "the", "original", "constructor", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Handle/InstanceHandle.php#L126-L137
train
eloquent/phony
src/Mock/Handle/InstanceHandle.php
InstanceHandle.proxy
public function proxy($object): Handle { $reflector = new ReflectionObject($object); foreach ($reflector->getMethods() as $method) { if ( $method->isStatic() || $method->isPrivate() || $method->isConstructor() || $method->isDestructor() ) { continue; } $name = $method->getName(); if ($this->class->hasMethod($name)) { $method->setAccessible(true); $this->stub($name)->doesWith( function ($arguments) use ($method, $object) { return $method->invokeArgs($object, $arguments->all()); }, [], false, true, false ); } } return $this; }
php
public function proxy($object): Handle { $reflector = new ReflectionObject($object); foreach ($reflector->getMethods() as $method) { if ( $method->isStatic() || $method->isPrivate() || $method->isConstructor() || $method->isDestructor() ) { continue; } $name = $method->getName(); if ($this->class->hasMethod($name)) { $method->setAccessible(true); $this->stub($name)->doesWith( function ($arguments) use ($method, $object) { return $method->invokeArgs($object, $arguments->all()); }, [], false, true, false ); } } return $this; }
[ "public", "function", "proxy", "(", "$", "object", ")", ":", "Handle", "{", "$", "reflector", "=", "new", "ReflectionObject", "(", "$", "object", ")", ";", "foreach", "(", "$", "reflector", "->", "getMethods", "(", ")", "as", "$", "method", ")", "{", ...
Use the supplied object as the implementation for all methods of the mock. This method may help when partial mocking of a particular implementation is not possible; as in the case of a final class. @param object $object The object to use. @return $this This handle.
[ "Use", "the", "supplied", "object", "as", "the", "implementation", "for", "all", "methods", "of", "the", "mock", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Handle/InstanceHandle.php#L174-L206
train
eloquent/phony
src/Spy/GeneratorSpyFactory.php
GeneratorSpyFactory.create
public function create(Call $call, Generator $generator): Generator { $spy = $this->createSpy($call, $generator); $spy->_phonySubject = $generator; return $spy; }
php
public function create(Call $call, Generator $generator): Generator { $spy = $this->createSpy($call, $generator); $spy->_phonySubject = $generator; return $spy; }
[ "public", "function", "create", "(", "Call", "$", "call", ",", "Generator", "$", "generator", ")", ":", "Generator", "{", "$", "spy", "=", "$", "this", "->", "createSpy", "(", "$", "call", ",", "$", "generator", ")", ";", "$", "spy", "->", "_phonySub...
Create a new generator spy. @param Call $call The call from which the generator originated. @param Generator $generator The generator. @return Generator The newly created generator spy.
[ "Create", "a", "new", "generator", "spy", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/GeneratorSpyFactory.php#L49-L55
train
eloquent/phony
src/Stub/StubVerifierFactory.php
StubVerifierFactory.create
public function create(Stub $stub = null, $self = null): StubVerifier { if (!$stub) { $stub = $this->stubFactory->create(); } $verifier = new StubVerifier( $stub, $this->spyFactory->create($stub), $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer, $this->generatorAnswerBuilderFactory ); if (func_num_args() > 1) { $verifier->setSelf($self); } else { $verifier->setSelf($verifier); } return $verifier; }
php
public function create(Stub $stub = null, $self = null): StubVerifier { if (!$stub) { $stub = $this->stubFactory->create(); } $verifier = new StubVerifier( $stub, $this->spyFactory->create($stub), $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer, $this->generatorAnswerBuilderFactory ); if (func_num_args() > 1) { $verifier->setSelf($self); } else { $verifier->setSelf($verifier); } return $verifier; }
[ "public", "function", "create", "(", "Stub", "$", "stub", "=", "null", ",", "$", "self", "=", "null", ")", ":", "StubVerifier", "{", "if", "(", "!", "$", "stub", ")", "{", "$", "stub", "=", "$", "this", "->", "stubFactory", "->", "create", "(", "...
Create a new stub verifier. If the "self" value is omitted, it will be set to the verifier itself. @param Stub|null $stub The stub, or null to create an anonymous stub. @param mixed $self The "self" value. @return StubVerifier The newly created stub verifier.
[ "Create", "a", "new", "stub", "verifier", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubVerifierFactory.php#L103-L129
train
eloquent/phony
src/Stub/StubVerifierFactory.php
StubVerifierFactory.createFromCallback
public function createFromCallback($callback): StubVerifier { $stub = $this->stubFactory->create($callback); $verifier = new StubVerifier( $stub, $this->spyFactory->create($stub), $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer, $this->generatorAnswerBuilderFactory ); $verifier->setSelf($verifier); return $verifier; }
php
public function createFromCallback($callback): StubVerifier { $stub = $this->stubFactory->create($callback); $verifier = new StubVerifier( $stub, $this->spyFactory->create($stub), $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer, $this->generatorAnswerBuilderFactory ); $verifier->setSelf($verifier); return $verifier; }
[ "public", "function", "createFromCallback", "(", "$", "callback", ")", ":", "StubVerifier", "{", "$", "stub", "=", "$", "this", "->", "stubFactory", "->", "create", "(", "$", "callback", ")", ";", "$", "verifier", "=", "new", "StubVerifier", "(", "$", "s...
Create a new stub verifier for the supplied callback. @param callable|null $callback The callback, or null to create an anonymous stub. @return StubVerifier The newly created stub verifier.
[ "Create", "a", "new", "stub", "verifier", "for", "the", "supplied", "callback", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubVerifierFactory.php#L138-L157
train
eloquent/phony
src/Stub/StubVerifierFactory.php
StubVerifierFactory.createGlobal
public function createGlobal( string $function, string $namespace ): StubVerifier { if (false !== strpos($function, '\\')) { throw new InvalidArgumentException( 'Only functions in the global namespace are supported.' ); } $namespace = trim($namespace, '\\'); if (!$namespace) { throw new InvalidArgumentException( 'The supplied namespace must not be empty.' ); } $stub = $this->stubFactory->create($function); $spy = $this->spyFactory->create($stub); $this->functionHookManager->defineFunction($function, $namespace, $spy); $verifier = new StubVerifier( $stub, $spy, $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer, $this->generatorAnswerBuilderFactory ); $verifier->setSelf($verifier); return $verifier; }
php
public function createGlobal( string $function, string $namespace ): StubVerifier { if (false !== strpos($function, '\\')) { throw new InvalidArgumentException( 'Only functions in the global namespace are supported.' ); } $namespace = trim($namespace, '\\'); if (!$namespace) { throw new InvalidArgumentException( 'The supplied namespace must not be empty.' ); } $stub = $this->stubFactory->create($function); $spy = $this->spyFactory->create($stub); $this->functionHookManager->defineFunction($function, $namespace, $spy); $verifier = new StubVerifier( $stub, $spy, $this->matcherFactory, $this->matcherVerifier, $this->generatorVerifierFactory, $this->iterableVerifierFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer, $this->generatorAnswerBuilderFactory ); $verifier->setSelf($verifier); return $verifier; }
[ "public", "function", "createGlobal", "(", "string", "$", "function", ",", "string", "$", "namespace", ")", ":", "StubVerifier", "{", "if", "(", "false", "!==", "strpos", "(", "$", "function", ",", "'\\\\'", ")", ")", "{", "throw", "new", "InvalidArgumentE...
Create a new stub verifier for a global function and declare it in the specified namespace. @param string $function The function name. @param string $namespace The namespace. @return StubVerifier The newly created stub verifier. @throws InvalidArgumentException If an invalid function name or namespace is specified.
[ "Create", "a", "new", "stub", "verifier", "for", "a", "global", "function", "and", "declare", "it", "in", "the", "specified", "namespace", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubVerifierFactory.php#L169-L206
train
scriptotek/php-marc
src/Fields/Field.php
Field.toString
protected function toString($codes, $options = []) { $glue = isset($options['glue']) ? $options['glue'] : static::$glue; return $this->clean(implode($glue, $this->getSubfieldValues($codes)), $options); }
php
protected function toString($codes, $options = []) { $glue = isset($options['glue']) ? $options['glue'] : static::$glue; return $this->clean(implode($glue, $this->getSubfieldValues($codes)), $options); }
[ "protected", "function", "toString", "(", "$", "codes", ",", "$", "options", "=", "[", "]", ")", "{", "$", "glue", "=", "isset", "(", "$", "options", "[", "'glue'", "]", ")", "?", "$", "options", "[", "'glue'", "]", ":", "static", "::", "$", "glu...
Return concatenated string of the given subfields. @param string[] $codes @param array $options @return string
[ "Return", "concatenated", "string", "of", "the", "given", "subfields", "." ]
79086165dfce9b9d2f490d38e9f50f70fef5641f
https://github.com/scriptotek/php-marc/blob/79086165dfce9b9d2f490d38e9f50f70fef5641f/src/Fields/Field.php#L95-L99
train
scriptotek/php-marc
src/Fields/Field.php
Field.asLineMarc
public function asLineMarc($sep = '$', $blank = ' ') { if ($this->field->isEmpty()) { return null; } $subfields = []; foreach ($this->field->getSubfields() as $sf) { $subfields[] = $sep . $sf->getCode() . ' ' . $sf->getData(); } $tag = $this->field->getTag(); $ind1 = $this->field->getIndicator(1); $ind2 = $this->field->getIndicator(2); if ($ind1 == ' ') { $ind1 = $blank; } if ($ind2 == ' ') { $ind2 = $blank; } return "${tag} ${ind1}${ind2} " . implode(' ', $subfields); }
php
public function asLineMarc($sep = '$', $blank = ' ') { if ($this->field->isEmpty()) { return null; } $subfields = []; foreach ($this->field->getSubfields() as $sf) { $subfields[] = $sep . $sf->getCode() . ' ' . $sf->getData(); } $tag = $this->field->getTag(); $ind1 = $this->field->getIndicator(1); $ind2 = $this->field->getIndicator(2); if ($ind1 == ' ') { $ind1 = $blank; } if ($ind2 == ' ') { $ind2 = $blank; } return "${tag} ${ind1}${ind2} " . implode(' ', $subfields); }
[ "public", "function", "asLineMarc", "(", "$", "sep", "=", "'$'", ",", "$", "blank", "=", "' '", ")", "{", "if", "(", "$", "this", "->", "field", "->", "isEmpty", "(", ")", ")", "{", "return", "null", ";", "}", "$", "subfields", "=", "[", "]", "...
Return a line MARC representation of the field. If the field is deleted, null is returned. @param string $sep Subfield separator character, defaults to '$' @param string $blank Blank indicator character, defaults to ' ' @return string|null.
[ "Return", "a", "line", "MARC", "representation", "of", "the", "field", ".", "If", "the", "field", "is", "deleted", "null", "is", "returned", "." ]
79086165dfce9b9d2f490d38e9f50f70fef5641f
https://github.com/scriptotek/php-marc/blob/79086165dfce9b9d2f490d38e9f50f70fef5641f/src/Fields/Field.php#L109-L129
train
scriptotek/php-marc
src/BibliographicRecord.php
BibliographicRecord.getCreators
public function getCreators($tag = null) { $tag = is_null($tag) ? [] : (is_array($tag) ? $tag : [$tag]); return array_values(array_filter(Person::get($this), function (Person $person) use ($tag) { return empty($tag) || in_array($person->getType(), $tag); })); }
php
public function getCreators($tag = null) { $tag = is_null($tag) ? [] : (is_array($tag) ? $tag : [$tag]); return array_values(array_filter(Person::get($this), function (Person $person) use ($tag) { return empty($tag) || in_array($person->getType(), $tag); })); }
[ "public", "function", "getCreators", "(", "$", "tag", "=", "null", ")", "{", "$", "tag", "=", "is_null", "(", "$", "tag", ")", "?", "[", "]", ":", "(", "is_array", "(", "$", "tag", ")", "?", "$", "tag", ":", "[", "$", "tag", "]", ")", ";", ...
Get an array of the 100 and 700 fields as `Person` objects, optionally filtered by tag. @param string|string[] $tag @return Person[]
[ "Get", "an", "array", "of", "the", "100", "and", "700", "fields", "as", "Person", "objects", "optionally", "filtered", "by", "tag", "." ]
79086165dfce9b9d2f490d38e9f50f70fef5641f
https://github.com/scriptotek/php-marc/blob/79086165dfce9b9d2f490d38e9f50f70fef5641f/src/BibliographicRecord.php#L176-L183
train
scriptotek/php-marc
src/Collection.php
Collection.getRecordType
public static function getRecordType(File_MARC_Record $record) { $leader = $record->getLeader(); $recordType = substr($leader, 6, 1); switch ($recordType) { case 'a': // Language material case 'c': // Notated music case 'd': // Manuscript notated music case 'e': // Cartographic material case 'f': // Manuscript cartographic material case 'g': // Projected medium case 'i': // Nonmusical sound recording case 'j': // Musical sound recording case 'k': // Two-dimensional nonprojectable graphic case 'm': // Computer file case 'o': // Kit case 'p': // Mixed materials case 'r': // Three-dimensional artifact or naturally occurring object case 't': // Manuscript language material return Marc21::BIBLIOGRAPHIC; case 'z': return Marc21::AUTHORITY; case 'u': // Unknown case 'v': // Multipart item holdings case 'x': // Single-part item holdings case 'y': // Serial item holdings return Marc21::HOLDINGS; default: throw new UnknownRecordType(); } }
php
public static function getRecordType(File_MARC_Record $record) { $leader = $record->getLeader(); $recordType = substr($leader, 6, 1); switch ($recordType) { case 'a': // Language material case 'c': // Notated music case 'd': // Manuscript notated music case 'e': // Cartographic material case 'f': // Manuscript cartographic material case 'g': // Projected medium case 'i': // Nonmusical sound recording case 'j': // Musical sound recording case 'k': // Two-dimensional nonprojectable graphic case 'm': // Computer file case 'o': // Kit case 'p': // Mixed materials case 'r': // Three-dimensional artifact or naturally occurring object case 't': // Manuscript language material return Marc21::BIBLIOGRAPHIC; case 'z': return Marc21::AUTHORITY; case 'u': // Unknown case 'v': // Multipart item holdings case 'x': // Single-part item holdings case 'y': // Serial item holdings return Marc21::HOLDINGS; default: throw new UnknownRecordType(); } }
[ "public", "static", "function", "getRecordType", "(", "File_MARC_Record", "$", "record", ")", "{", "$", "leader", "=", "$", "record", "->", "getLeader", "(", ")", ";", "$", "recordType", "=", "substr", "(", "$", "leader", ",", "6", ",", "1", ")", ";", ...
Determines if a record is a bibliographic, holdings or authority record. @param File_MARC_Record $record @return string
[ "Determines", "if", "a", "record", "is", "a", "bibliographic", "holdings", "or", "authority", "record", "." ]
79086165dfce9b9d2f490d38e9f50f70fef5641f
https://github.com/scriptotek/php-marc/blob/79086165dfce9b9d2f490d38e9f50f70fef5641f/src/Collection.php#L59-L90
train
scriptotek/php-marc
src/Collection.php
Collection.recordFactory
public function recordFactory(File_MARC_Record $record) { try { $recordType = self::getRecordType($record); } catch (UnknownRecordType $e) { return new Record($record); } switch ($recordType) { case Marc21::BIBLIOGRAPHIC: return new BibliographicRecord($record); case Marc21::HOLDINGS: return new HoldingsRecord($record); case Marc21::AUTHORITY: return new AuthorityRecord($record); } }
php
public function recordFactory(File_MARC_Record $record) { try { $recordType = self::getRecordType($record); } catch (UnknownRecordType $e) { return new Record($record); } switch ($recordType) { case Marc21::BIBLIOGRAPHIC: return new BibliographicRecord($record); case Marc21::HOLDINGS: return new HoldingsRecord($record); case Marc21::AUTHORITY: return new AuthorityRecord($record); } }
[ "public", "function", "recordFactory", "(", "File_MARC_Record", "$", "record", ")", "{", "try", "{", "$", "recordType", "=", "self", "::", "getRecordType", "(", "$", "record", ")", ";", "}", "catch", "(", "UnknownRecordType", "$", "e", ")", "{", "return", ...
Creates a Record object from a File_MARC_Record object. @param File_MARC_Record $record @return AuthorityRecord|BibliographicRecord|HoldingsRecord
[ "Creates", "a", "Record", "object", "from", "a", "File_MARC_Record", "object", "." ]
79086165dfce9b9d2f490d38e9f50f70fef5641f
https://github.com/scriptotek/php-marc/blob/79086165dfce9b9d2f490d38e9f50f70fef5641f/src/Collection.php#L108-L125
train
wayfair/hypernova-php
src/Renderer.php
Renderer.addJob
public function addJob($id, $job) { if (is_array($job)) { $job = Job::fromArray($job); } $this->incomingJobs[$id] = $job; }
php
public function addJob($id, $job) { if (is_array($job)) { $job = Job::fromArray($job); } $this->incomingJobs[$id] = $job; }
[ "public", "function", "addJob", "(", "$", "id", ",", "$", "job", ")", "{", "if", "(", "is_array", "(", "$", "job", ")", ")", "{", "$", "job", "=", "Job", "::", "fromArray", "(", "$", "job", ")", ";", "}", "$", "this", "->", "incomingJobs", "[",...
Add a job @param string $id @param \WF\Hypernova\Job|array $job Job to add, { [view]: { name: String, data: ReactProps } }
[ "Add", "a", "job" ]
0b352762eab4a78bf27a8a1b25405d5cf4281460
https://github.com/wayfair/hypernova-php/blob/0b352762eab4a78bf27a8a1b25405d5cf4281460/src/Renderer.php#L73-L79
train
wayfair/hypernova-php
src/Renderer.php
Renderer.render
public function render() { $jobs = $this->createJobs(); try { list($shouldSendRequest, $jobs) = $this->prepareRequest($jobs); if (!$shouldSendRequest) { return $this->fallback(null, $jobs); } } catch (\Exception $e) { return $this->fallback($e, $jobs); } try { return $this->makeRequest($jobs); } catch (\Exception $e) { return $this->fallback($e, $jobs); } }
php
public function render() { $jobs = $this->createJobs(); try { list($shouldSendRequest, $jobs) = $this->prepareRequest($jobs); if (!$shouldSendRequest) { return $this->fallback(null, $jobs); } } catch (\Exception $e) { return $this->fallback($e, $jobs); } try { return $this->makeRequest($jobs); } catch (\Exception $e) { return $this->fallback($e, $jobs); } }
[ "public", "function", "render", "(", ")", "{", "$", "jobs", "=", "$", "this", "->", "createJobs", "(", ")", ";", "try", "{", "list", "(", "$", "shouldSendRequest", ",", "$", "jobs", ")", "=", "$", "this", "->", "prepareRequest", "(", "$", "jobs", "...
Do the things. @return \WF\Hypernova\Response
[ "Do", "the", "things", "." ]
0b352762eab4a78bf27a8a1b25405d5cf4281460
https://github.com/wayfair/hypernova-php/blob/0b352762eab4a78bf27a8a1b25405d5cf4281460/src/Renderer.php#L86-L103
train
drupal-code-builder/drupal-code-builder
Task/ReportHookPresets.php
ReportHookPresets.loadPresetsFile
protected function loadPresetsFile($filename) { $pieces = array('templates', $this->environment->getCoreMajorVersion(), $filename); $path = $this->environment->getPath(implode('/', $pieces)); if (!file_exists($path)) { throw new \Exception(strtr("Unable to find template at !path.", array( '!path' => htmlspecialchars($path, ENT_QUOTES, 'UTF-8'), ))); } $template_file = file_get_contents($path); return $template_file; }
php
protected function loadPresetsFile($filename) { $pieces = array('templates', $this->environment->getCoreMajorVersion(), $filename); $path = $this->environment->getPath(implode('/', $pieces)); if (!file_exists($path)) { throw new \Exception(strtr("Unable to find template at !path.", array( '!path' => htmlspecialchars($path, ENT_QUOTES, 'UTF-8'), ))); } $template_file = file_get_contents($path); return $template_file; }
[ "protected", "function", "loadPresetsFile", "(", "$", "filename", ")", "{", "$", "pieces", "=", "array", "(", "'templates'", ",", "$", "this", "->", "environment", "->", "getCoreMajorVersion", "(", ")", ",", "$", "filename", ")", ";", "$", "path", "=", "...
Returns the contents of a template file. TODO: this will eventually return either the user version or the module version. TODO: IS THIS IN THE RIGHT FILE??? @param $filename The filename of the template file to read. @return The contents of the file, or NULL if the file is not found. @throws \Exception Throws an exception if the file can't be found.
[ "Returns", "the", "contents", "of", "a", "template", "file", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookPresets.php#L35-L47
train
drupal-code-builder/drupal-code-builder
Task/ReportHookPresets.php
ReportHookPresets.getHookPresets
function getHookPresets() { // TODO: read user file preferentially. $presets_template = $this->loadPresetsFile('hook_groups.template'); $hook_presets = json_decode(preg_replace("@//.*@", '', $presets_template), TRUE); if (is_null($hook_presets)) { // @TODO: do something here to say its gone wrong. Throw Exception? drupal_set_message(t('Problem reading json file.'), 'error'); } return $hook_presets; }
php
function getHookPresets() { // TODO: read user file preferentially. $presets_template = $this->loadPresetsFile('hook_groups.template'); $hook_presets = json_decode(preg_replace("@//.*@", '', $presets_template), TRUE); if (is_null($hook_presets)) { // @TODO: do something here to say its gone wrong. Throw Exception? drupal_set_message(t('Problem reading json file.'), 'error'); } return $hook_presets; }
[ "function", "getHookPresets", "(", ")", "{", "// TODO: read user file preferentially.", "$", "presets_template", "=", "$", "this", "->", "loadPresetsFile", "(", "'hook_groups.template'", ")", ";", "$", "hook_presets", "=", "json_decode", "(", "preg_replace", "(", "\"@...
Get the definition of hook presets. A preset is a collection of hooks with a machine name and a descriptive label. Presets allow quick selection of hooks that are commonly used together, eg those used to define a node type, or blocks. @return An array keyed by preset name, whose values are arrays of the form: 'label': The label shown to the user. 'hooks': A flat array of full hook names, eg 'hook_menu'.
[ "Get", "the", "definition", "of", "hook", "presets", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookPresets.php#L61-L70
train
drupal-code-builder/drupal-code-builder
Generator/BaseGenerator.php
BaseGenerator.getComponentDataValue
public function getComponentDataValue($name) { if (!isset($this->component_data[$name])) { throw new \Exception(strtr("Property @name not found in data for @type.", [ '@name' => $name, '@type' => get_class($this), ])); } return $this->component_data[$name]; }
php
public function getComponentDataValue($name) { if (!isset($this->component_data[$name])) { throw new \Exception(strtr("Property @name not found in data for @type.", [ '@name' => $name, '@type' => get_class($this), ])); } return $this->component_data[$name]; }
[ "public", "function", "getComponentDataValue", "(", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "component_data", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "strtr", "(", "\"Property @name no...
Get the value of a component property. @param string $name The property name. @return mixed The value.
[ "Get", "the", "value", "of", "a", "component", "property", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/BaseGenerator.php#L312-L321
train
drupal-code-builder/drupal-code-builder
Generator/BaseGenerator.php
BaseGenerator.mergeComponentData
public function mergeComponentData($additional_component_data) { $differences_merged = FALSE; // Get the property info for just this component: we don't care about // going into compound properties. $component_property_info = static::componentDataDefinition(); // Only merge array properties. foreach ($component_property_info as $property_name => $property_info) { // Skip this property if there's nothing here. if (!isset($this->component_data[$property_name]) && !isset($additional_component_data[$property_name])) { continue; } // We're getting the component data direct, so it won't have default // attributes filled in: 'format' might not be set. if (!isset($property_info['format']) || $property_info['format'] != 'array') { // Don't merge this property, but check that we're not throwing away // data from the additional data. assert($this->component_data[$property_name] == $additional_component_data[$property_name], "Attempted to discard request for new component, but failed on property $property_name with existing data " . print_r($this->component_data, TRUE) . " and new data " . print_r($additional_component_data, TRUE) ); continue; } if ($this->component_data[$property_name] != $additional_component_data[$property_name]) { $differences_merged = TRUE; $this->component_data[$property_name] = array_merge_recursive($this->component_data[$property_name], $additional_component_data[$property_name]); } } return $differences_merged; }
php
public function mergeComponentData($additional_component_data) { $differences_merged = FALSE; // Get the property info for just this component: we don't care about // going into compound properties. $component_property_info = static::componentDataDefinition(); // Only merge array properties. foreach ($component_property_info as $property_name => $property_info) { // Skip this property if there's nothing here. if (!isset($this->component_data[$property_name]) && !isset($additional_component_data[$property_name])) { continue; } // We're getting the component data direct, so it won't have default // attributes filled in: 'format' might not be set. if (!isset($property_info['format']) || $property_info['format'] != 'array') { // Don't merge this property, but check that we're not throwing away // data from the additional data. assert($this->component_data[$property_name] == $additional_component_data[$property_name], "Attempted to discard request for new component, but failed on property $property_name with existing data " . print_r($this->component_data, TRUE) . " and new data " . print_r($additional_component_data, TRUE) ); continue; } if ($this->component_data[$property_name] != $additional_component_data[$property_name]) { $differences_merged = TRUE; $this->component_data[$property_name] = array_merge_recursive($this->component_data[$property_name], $additional_component_data[$property_name]); } } return $differences_merged; }
[ "public", "function", "mergeComponentData", "(", "$", "additional_component_data", ")", "{", "$", "differences_merged", "=", "FALSE", ";", "// Get the property info for just this component: we don't care about", "// going into compound properties.", "$", "component_property_info", ...
Merge data from additional requests of a component. @param array $additional_component_data The array of new component data to merge in. This has the same format as the parameter to __construct(). @return bool Boolean indicating whether any data needed to be merged: TRUE if so, FALSE if nothing was merged because all values were the same.
[ "Merge", "data", "from", "additional", "requests", "of", "a", "component", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/BaseGenerator.php#L358-L395
train
drupal-code-builder/drupal-code-builder
Generator/BaseGenerator.php
BaseGenerator.filterComponentContentsForRole
protected function filterComponentContentsForRole($contents, $role) { $return = []; foreach ($contents as $key => $item) { if ($item['role'] == $role) { $return[$key] = $item['content']; } } return $return; }
php
protected function filterComponentContentsForRole($contents, $role) { $return = []; foreach ($contents as $key => $item) { if ($item['role'] == $role) { $return[$key] = $item['content']; } } return $return; }
[ "protected", "function", "filterComponentContentsForRole", "(", "$", "contents", ",", "$", "role", ")", "{", "$", "return", "=", "[", "]", ";", "foreach", "(", "$", "contents", "as", "$", "key", "=>", "$", "item", ")", "{", "if", "(", "$", "item", "[...
Filters an array of child contents by role. Helper for buildComponentContents(). @param $contents The array of contents as returned by an implementation of buildComponentContents(). @param $role A role name, as used in the 'role' property of the $contents array. @return An array of the 'content' data of the given array items that matched the role, keyed by the same key as the the given array item.
[ "Filters", "an", "array", "of", "child", "contents", "by", "role", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/BaseGenerator.php#L512-L520
train
drupal-code-builder/drupal-code-builder
Generator/Hooks.php
Hooks.parseTemplate
function parseTemplate($file) { $data = array(); // Captures a template name and body from a template file. $pattern = '#== START (.*?) ==(.*?)== END ==#ms'; preg_match_all($pattern, $file, $matches); $count = count($matches[0]); for ($i = 0; $i < $count; $i++) { $data[$matches[1][$i]] = array( #'title' => $matches[1][$i], 'template' => $matches[2][$i] ); /* $hook_custom_declarations[] = array( 'title' => $matches[1][$i], 'data' => $matches[2][$i] ); */ } return $data; }
php
function parseTemplate($file) { $data = array(); // Captures a template name and body from a template file. $pattern = '#== START (.*?) ==(.*?)== END ==#ms'; preg_match_all($pattern, $file, $matches); $count = count($matches[0]); for ($i = 0; $i < $count; $i++) { $data[$matches[1][$i]] = array( #'title' => $matches[1][$i], 'template' => $matches[2][$i] ); /* $hook_custom_declarations[] = array( 'title' => $matches[1][$i], 'data' => $matches[2][$i] ); */ } return $data; }
[ "function", "parseTemplate", "(", "$", "file", ")", "{", "$", "data", "=", "array", "(", ")", ";", "// Captures a template name and body from a template file.", "$", "pattern", "=", "'#== START (.*?) ==(.*?)== END ==#ms'", ";", "preg_match_all", "(", "$", "pattern", "...
Parse a drupal_code_builder template file. Template files are composed of several sections in the form of: == START [title of template section] == [the body of the template section] == END == @param string $file The template file to parse @return Array Return array keyed by hook name, whose values are of the form: array('template' => TEMPLATE BODY)
[ "Parse", "a", "drupal_code_builder", "template", "file", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Hooks.php#L375-L395
train
drupal-code-builder/drupal-code-builder
Task/ReportHookData.php
ReportHookData.listHookData
function listHookData() { // We may come here several times, so cache this. if (!empty($this->hook_data)) { return $this->hook_data; } $this->hook_data = $this->environment->getStorage()->retrieve('hooks'); return $this->hook_data; }
php
function listHookData() { // We may come here several times, so cache this. if (!empty($this->hook_data)) { return $this->hook_data; } $this->hook_data = $this->environment->getStorage()->retrieve('hooks'); return $this->hook_data; }
[ "function", "listHookData", "(", ")", "{", "// We may come here several times, so cache this.", "if", "(", "!", "empty", "(", "$", "this", "->", "hook_data", ")", ")", "{", "return", "$", "this", "->", "hook_data", ";", "}", "$", "this", "->", "hook_data", "...
Get the list of hook data. @return The processed hook data.
[ "Get", "the", "list", "of", "hook", "data", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookData.php#L35-L43
train
drupal-code-builder/drupal-code-builder
Task/ReportHookData.php
ReportHookData.listHookNames
function listHookNames($style = 'full') { $data = $this->getHookDeclarations(); $names = array_keys($data); if ($style == 'short') { foreach ($names as $key => $hook_name) { $names[$key] = str_replace('hook_', '', $hook_name); } } return $names; }
php
function listHookNames($style = 'full') { $data = $this->getHookDeclarations(); $names = array_keys($data); if ($style == 'short') { foreach ($names as $key => $hook_name) { $names[$key] = str_replace('hook_', '', $hook_name); } } return $names; }
[ "function", "listHookNames", "(", "$", "style", "=", "'full'", ")", "{", "$", "data", "=", "$", "this", "->", "getHookDeclarations", "(", ")", ";", "$", "names", "=", "array_keys", "(", "$", "data", ")", ";", "if", "(", "$", "style", "==", "'short'",...
Get just hook names. @param $style Whether to return hook names as just 'init' or 'hook_init'. One of: - 'short': Return short names, i.e., 'init'. - 'full': Return full hook names, i.e., 'hook_init'. @return A flat array of strings.
[ "Get", "just", "hook", "names", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookData.php#L56-L67
train
drupal-code-builder/drupal-code-builder
Task/ReportHookData.php
ReportHookData.listHookNamesOptions
function listHookNamesOptions() { $data = $this->getHookDeclarations(); $return = array(); foreach ($data as $hook_name => $hook_info) { $return[$hook_name] = $hook_info['description']; } return $return; }
php
function listHookNamesOptions() { $data = $this->getHookDeclarations(); $return = array(); foreach ($data as $hook_name => $hook_info) { $return[$hook_name] = $hook_info['description']; } return $return; }
[ "function", "listHookNamesOptions", "(", ")", "{", "$", "data", "=", "$", "this", "->", "getHookDeclarations", "(", ")", ";", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "hook_name", "=>", "$", "hook_info", ")", ...
Get hooks as a list of options. @return An array of hooks as options suitable for FormAPI, where each key is a full hook name, and each value is a description.
[ "Get", "hooks", "as", "a", "list", "of", "options", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookData.php#L76-L85
train
drupal-code-builder/drupal-code-builder
Task/ReportHookData.php
ReportHookData.listHookOptionsStructured
public function listHookOptionsStructured() { $data = $this->getHookDeclarations(); $return = array(); foreach ($data as $hook_name => $hook_info) { $return[$hook_info['group']][$hook_name] = array( 'name' => $hook_info['name'], 'description' => $hook_info['description'], 'type' => $hook_info['type'], 'core' => $hook_info['core'], ); } return $return; }
php
public function listHookOptionsStructured() { $data = $this->getHookDeclarations(); $return = array(); foreach ($data as $hook_name => $hook_info) { $return[$hook_info['group']][$hook_name] = array( 'name' => $hook_info['name'], 'description' => $hook_info['description'], 'type' => $hook_info['type'], 'core' => $hook_info['core'], ); } return $return; }
[ "public", "function", "listHookOptionsStructured", "(", ")", "{", "$", "data", "=", "$", "this", "->", "getHookDeclarations", "(", ")", ";", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "hook_name", "=>", "$", "ho...
Get hooks as a grouped list with data about each item. @return An array keyed by hook group, whose items are in turn arrays keyed by hook name standardized to lowercase, and whose items in turn are arrays with the following properties: - 'name': The hook name in the original case. - 'type' One of 'hook' or 'callback'. - 'description' The first line from the hook definition's docblock.
[ "Get", "hooks", "as", "a", "grouped", "list", "with", "data", "about", "each", "item", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookData.php#L98-L112
train
drupal-code-builder/drupal-code-builder
Task/ReportHookData.php
ReportHookData.getHookDeclarations
function getHookDeclarations() { $data = $this->listHookData(); $return = array(); foreach ($data as $group => $hooks) { foreach ($hooks as $key => $hook) { // Standardize to lowercase. $hook_name = strtolower($hook['name']); $return[$hook_name] = $hook; } } return $return; }
php
function getHookDeclarations() { $data = $this->listHookData(); $return = array(); foreach ($data as $group => $hooks) { foreach ($hooks as $key => $hook) { // Standardize to lowercase. $hook_name = strtolower($hook['name']); $return[$hook_name] = $hook; } } return $return; }
[ "function", "getHookDeclarations", "(", ")", "{", "$", "data", "=", "$", "this", "->", "listHookData", "(", ")", ";", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "group", "=>", "$", "hooks", ")", "{", "foreac...
Get stored hook declarations, keyed by hook name, with destination. @return An array of hook information, keyed by the full name of the hook standardized to lower case. Each item has the keys: - 'type': One of 'hook' or 'callback'. - 'name': The full name of the hook in the original case, eg 'hook_form_FORM_ID_alter'. - 'definition': The full function declaration. - 'description': The first line of the hook docblock. - 'destination': The file this hook should be placed in, as a module file pattern such as '%module.module'. - 'dependencies': TODO! - 'group': Erm write this later. - 'file_path': The absolute path of the file this definition was taken from. - 'body': The hook function body, taken from the API file.
[ "Get", "stored", "hook", "declarations", "keyed", "by", "hook", "name", "with", "destination", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookData.php#L134-L148
train
drupal-code-builder/drupal-code-builder
Utility/InsertArray.php
InsertArray.insert
protected static function insert(&$array, $key, $insert_array, $before) { if (!isset($array[$key])) { throw new \Exception("The array does not have the key $key."); } if ($before) { $offset = 0; } else { $offset = 1; } $pos = array_search($key, array_keys($array)); $pos += $offset; $array_before = array_slice($array, 0, $pos); $array_after = array_slice($array, $pos); $array = array_merge( $array_before, $insert_array, $array_after ); }
php
protected static function insert(&$array, $key, $insert_array, $before) { if (!isset($array[$key])) { throw new \Exception("The array does not have the key $key."); } if ($before) { $offset = 0; } else { $offset = 1; } $pos = array_search($key, array_keys($array)); $pos += $offset; $array_before = array_slice($array, 0, $pos); $array_after = array_slice($array, $pos); $array = array_merge( $array_before, $insert_array, $array_after ); }
[ "protected", "static", "function", "insert", "(", "&", "$", "array", ",", "$", "key", ",", "$", "insert_array", ",", "$", "before", ")", "{", "if", "(", "!", "isset", "(", "$", "array", "[", "$", "key", "]", ")", ")", "{", "throw", "new", "\\", ...
Inserts values into an array before or after a given key. Helper for insertBefore() and insertAfter(). Values from $insert_array are inserted into $array either before or after $key. @param array $array The array to insert into, passed by reference and altered in place. @param mixed $key The key of $array to insert before or after. @param array $insert_array An array whose values should be inserted. @param bool $before If TRUE, insert before the given key; if FALSE, insert after it. @throws \Exception Throws an exception if the array does not have the key $key.
[ "Inserts", "values", "into", "an", "array", "before", "or", "after", "a", "given", "key", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Utility/InsertArray.php#L73-L96
train
drupal-code-builder/drupal-code-builder
Task/Collect/ContainerBuilderGetter.php
ContainerBuilderGetter.getContainerBuilder
public function getContainerBuilder() { if (!isset($this->containerBuilder)) { // Get the kernel, and hack it to get a compiled container. // We need this rather than the normal cached container, as that doesn't // allow us to get the full service definitions. $kernel = \Drupal::service('kernel'); $kernel_R = new \ReflectionClass($kernel); $compileContainer_R = $kernel_R->getMethod('compileContainer'); $compileContainer_R->setAccessible(TRUE); $this->containerBuilder = $compileContainer_R->invoke($kernel); } return $this->containerBuilder; }
php
public function getContainerBuilder() { if (!isset($this->containerBuilder)) { // Get the kernel, and hack it to get a compiled container. // We need this rather than the normal cached container, as that doesn't // allow us to get the full service definitions. $kernel = \Drupal::service('kernel'); $kernel_R = new \ReflectionClass($kernel); $compileContainer_R = $kernel_R->getMethod('compileContainer'); $compileContainer_R->setAccessible(TRUE); $this->containerBuilder = $compileContainer_R->invoke($kernel); } return $this->containerBuilder; }
[ "public", "function", "getContainerBuilder", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "containerBuilder", ")", ")", "{", "// Get the kernel, and hack it to get a compiled container.", "// We need this rather than the normal cached container, as that doesn...
Gets the ContainerBuilder by hacking the Drupal kernel. @return The container builder.
[ "Gets", "the", "ContainerBuilder", "by", "hacking", "the", "Drupal", "kernel", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/ContainerBuilderGetter.php#L21-L36
train
drupal-code-builder/drupal-code-builder
Task/Collect/CodeAnalyser.php
CodeAnalyser.classIsUsable
public function classIsUsable($qualified_classname) { // Set up the script with its autoloader if not already done so. We keep the // resource to the process open between calls to this method. // This means we only need to start a new process at the start of a request // to DCB and after a bad class has caused the script to crash. if (!is_resource($this->checking_script_resource)) { $this->setupScript(); } // Write the class to check to the script's STDIN. $status = $this->sendCommand('CLASS', $qualified_classname); if (!$status) { // The process has crashed. // Clean up so the script is reinitialized the next time this method is // called. $this->closeScript(); } // Return the status of the class check: TRUE means the class is usable, // FALSE means it is broken and a class_exists() causes a crash. return $status; }
php
public function classIsUsable($qualified_classname) { // Set up the script with its autoloader if not already done so. We keep the // resource to the process open between calls to this method. // This means we only need to start a new process at the start of a request // to DCB and after a bad class has caused the script to crash. if (!is_resource($this->checking_script_resource)) { $this->setupScript(); } // Write the class to check to the script's STDIN. $status = $this->sendCommand('CLASS', $qualified_classname); if (!$status) { // The process has crashed. // Clean up so the script is reinitialized the next time this method is // called. $this->closeScript(); } // Return the status of the class check: TRUE means the class is usable, // FALSE means it is broken and a class_exists() causes a crash. return $status; }
[ "public", "function", "classIsUsable", "(", "$", "qualified_classname", ")", "{", "// Set up the script with its autoloader if not already done so. We keep the", "// resource to the process open between calls to this method.", "// This means we only need to start a new process at the start of a ...
Determines whether a class may be instantiated safely. This is needed because: - lots of contrib modules have plugins that simply crash on class load, typically because they fail the interface implementation. - modules can have services which are meant for another non-dependent module's use, and which can thus implement interfaces or inherit from classes which are not present. For example, in the case of a tagged service, if the collecting module is not enabled, we have no way of detecting that the service's tag is a service collector tag. @param string $qualified_classname The fully-qualified class name, without the initial \. @return boolean TRUE if the class may be used (but note this does not say whether it actually exists); FALSE if the class should not be used as attempting to will cause a PHP fatal error.
[ "Determines", "whether", "a", "class", "may", "be", "instantiated", "safely", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/CodeAnalyser.php#L65-L87
train
drupal-code-builder/drupal-code-builder
Task/Collect/CodeAnalyser.php
CodeAnalyser.setupScript
protected function setupScript() { // The PHP that proc_open() will find may not be the same one as run by // the webserver, and indeed, on some systems may be an out-of-date version, // so detect the PHP that we're currently running and ensure we use that. $php = PHP_BINDIR . '/php'; $script_name = __DIR__ . '/../../class_safety_checker.php'; $drupal_root = $this->environment->getRoot(); $autoloader_filepath = $drupal_root . '/autoload.php'; // We need to pass all the dynamic namespaces to the script, as Composer's // generated autoloader knows only about /vendor and /core/lib, but not // modules. // This code is taken from DrupalKernel::attachSynthetic(). $container = $this->environment->getContainer(); $namespaces = $container->getParameter('container.namespaces'); $psr4 = []; foreach ($namespaces as $prefix => $paths) { if (is_array($paths)) { foreach ($paths as $key => $value) { $paths[$key] = $drupal_root . '/' . $value; } } elseif (is_string($paths)) { $paths = $drupal_root . '/' . $paths; } // Build a list of data to pass to the script on STDIN. // $paths is never an array, AFAICT. $psr4[] = $prefix . '\\' . '::' . $paths; } // Debug option for the script. $debug_int = (int) $this->debug; $command = "{$php} {$script_name} '{$autoloader_filepath}' {$debug_int}"; // Open pipes for both input and output. $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w") ); $this->checking_script_resource = proc_open($command, $descriptorspec, $this->pipes); if (!is_resource($this->checking_script_resource)) { throw new \Exception("Could not create process for classIsUsable()."); } foreach ($psr4 as $line) { $this->sendCommand('PSR4', $line); } }
php
protected function setupScript() { // The PHP that proc_open() will find may not be the same one as run by // the webserver, and indeed, on some systems may be an out-of-date version, // so detect the PHP that we're currently running and ensure we use that. $php = PHP_BINDIR . '/php'; $script_name = __DIR__ . '/../../class_safety_checker.php'; $drupal_root = $this->environment->getRoot(); $autoloader_filepath = $drupal_root . '/autoload.php'; // We need to pass all the dynamic namespaces to the script, as Composer's // generated autoloader knows only about /vendor and /core/lib, but not // modules. // This code is taken from DrupalKernel::attachSynthetic(). $container = $this->environment->getContainer(); $namespaces = $container->getParameter('container.namespaces'); $psr4 = []; foreach ($namespaces as $prefix => $paths) { if (is_array($paths)) { foreach ($paths as $key => $value) { $paths[$key] = $drupal_root . '/' . $value; } } elseif (is_string($paths)) { $paths = $drupal_root . '/' . $paths; } // Build a list of data to pass to the script on STDIN. // $paths is never an array, AFAICT. $psr4[] = $prefix . '\\' . '::' . $paths; } // Debug option for the script. $debug_int = (int) $this->debug; $command = "{$php} {$script_name} '{$autoloader_filepath}' {$debug_int}"; // Open pipes for both input and output. $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w") ); $this->checking_script_resource = proc_open($command, $descriptorspec, $this->pipes); if (!is_resource($this->checking_script_resource)) { throw new \Exception("Could not create process for classIsUsable()."); } foreach ($psr4 as $line) { $this->sendCommand('PSR4', $line); } }
[ "protected", "function", "setupScript", "(", ")", "{", "// The PHP that proc_open() will find may not be the same one as run by", "// the webserver, and indeed, on some systems may be an out-of-date version,", "// so detect the PHP that we're currently running and ensure we use that.", "$", "php...
Starts a process running the class safety script.
[ "Starts", "a", "process", "running", "the", "class", "safety", "script", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/CodeAnalyser.php#L92-L143
train
drupal-code-builder/drupal-code-builder
Task/Collect/CodeAnalyser.php
CodeAnalyser.sendCommand
protected function sendCommand($command, $payload) { fwrite($this->pipes[0], $command . ':' . $payload . PHP_EOL); $status_line = trim(fgets($this->pipes[1])); // An empty status line means the script has stopped responding, and has // presumably crashed. if (empty($status_line)) { return FALSE; } // An expected status line that matches the sent command means everything // went fine. if ($status_line == "$command OK") { return TRUE; } // If something's gone wrong, get any further output from the script so we // can see error messages. while ($line = fgets($this->pipes[1])) { dump($line); } throw new \Exception("Command $command with payload '$payload' failed."); }
php
protected function sendCommand($command, $payload) { fwrite($this->pipes[0], $command . ':' . $payload . PHP_EOL); $status_line = trim(fgets($this->pipes[1])); // An empty status line means the script has stopped responding, and has // presumably crashed. if (empty($status_line)) { return FALSE; } // An expected status line that matches the sent command means everything // went fine. if ($status_line == "$command OK") { return TRUE; } // If something's gone wrong, get any further output from the script so we // can see error messages. while ($line = fgets($this->pipes[1])) { dump($line); } throw new \Exception("Command $command with payload '$payload' failed."); }
[ "protected", "function", "sendCommand", "(", "$", "command", ",", "$", "payload", ")", "{", "fwrite", "(", "$", "this", "->", "pipes", "[", "0", "]", ",", "$", "command", ".", "':'", ".", "$", "payload", ".", "PHP_EOL", ")", ";", "$", "status_line", ...
Send a single command to the script. @param string $command The command to send to the script. One of: - 'PSR4': A PSR4 namespace and folder to add to the autoloader. - 'CLASS': A class to check. @param string $payload The value to send to the script. Format depends on the command. @return bool Returns TRUE if the command was successful; FALSE if the process appears to have crashed. @throws \Exception Throws an exception if the command failed.
[ "Send", "a", "single", "command", "to", "the", "script", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/CodeAnalyser.php#L162-L186
train
drupal-code-builder/drupal-code-builder
Task/Collect/CodeAnalyser.php
CodeAnalyser.closeScript
public function closeScript() { fclose($this->pipes[0]); fclose($this->pipes[1]); proc_close($this->checking_script_resource); }
php
public function closeScript() { fclose($this->pipes[0]); fclose($this->pipes[1]); proc_close($this->checking_script_resource); }
[ "public", "function", "closeScript", "(", ")", "{", "fclose", "(", "$", "this", "->", "pipes", "[", "0", "]", ")", ";", "fclose", "(", "$", "this", "->", "pipes", "[", "1", "]", ")", ";", "proc_close", "(", "$", "this", "->", "checking_script_resourc...
Close the script. Note this is called automatically when this object is destroyed.
[ "Close", "the", "script", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/CodeAnalyser.php#L193-L197
train
drupal-code-builder/drupal-code-builder
Generator/FormattingTrait/PHPFormattingTrait.php
PHPFormattingTrait.docBlock
function docBlock($lines) { if (!is_array($lines)) { $lines = array($lines); } $lines = array_merge( array("/**"), array_map(function ($line) { if (empty($line)) { return ' *'; } return " * $line"; }, $lines), array(" */") ); return $lines; }
php
function docBlock($lines) { if (!is_array($lines)) { $lines = array($lines); } $lines = array_merge( array("/**"), array_map(function ($line) { if (empty($line)) { return ' *'; } return " * $line"; }, $lines), array(" */") ); return $lines; }
[ "function", "docBlock", "(", "$", "lines", ")", "{", "if", "(", "!", "is_array", "(", "$", "lines", ")", ")", "{", "$", "lines", "=", "array", "(", "$", "lines", ")", ";", "}", "$", "lines", "=", "array_merge", "(", "array", "(", "\"/**\"", ")", ...
Helper to format text as docblock. @param @lines An array of lines, or a single line of text. Lines to be normally indented should have no leading whitespace. @return An array of lines for the docblock with start and end PHP comment markers.
[ "Helper", "to", "format", "text", "as", "docblock", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/FormattingTrait/PHPFormattingTrait.php#L20-L37
train
drupal-code-builder/drupal-code-builder
Generator/FormattingTrait/PHPFormattingTrait.php
PHPFormattingTrait.indentCodeLines
function indentCodeLines($lines, $indent = 1) { $indent = str_repeat(' ', $indent); $indented_lines = array_map(function ($line) use ($indent) { return empty($line) ? $line : $indent . $line; }, $lines); return $indented_lines; }
php
function indentCodeLines($lines, $indent = 1) { $indent = str_repeat(' ', $indent); $indented_lines = array_map(function ($line) use ($indent) { return empty($line) ? $line : $indent . $line; }, $lines); return $indented_lines; }
[ "function", "indentCodeLines", "(", "$", "lines", ",", "$", "indent", "=", "1", ")", "{", "$", "indent", "=", "str_repeat", "(", "' '", ",", "$", "indent", ")", ";", "$", "indented_lines", "=", "array_map", "(", "function", "(", "$", "line", ")", "u...
Indent all the non-empty lines in a block of code. @param array $lines An array of code lines. @param int $indent (optional) The number of indentation levels to add. Defaults to 1, that is, an indentation of two spaces. @return The array of code lines with the indentation applied.
[ "Indent", "all", "the", "non", "-", "empty", "lines", "in", "a", "block", "of", "code", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/FormattingTrait/PHPFormattingTrait.php#L51-L58
train
drupal-code-builder/drupal-code-builder
Utility/NestedArray.php
NestedArray.filter
public static function filter(array $array, callable $callable = NULL) { $array = is_callable($callable) ? array_filter($array, $callable) : array_filter($array); foreach ($array as &$element) { if (is_array($element)) { $element = static::filter($element, $callable); } } return $array; }
php
public static function filter(array $array, callable $callable = NULL) { $array = is_callable($callable) ? array_filter($array, $callable) : array_filter($array); foreach ($array as &$element) { if (is_array($element)) { $element = static::filter($element, $callable); } } return $array; }
[ "public", "static", "function", "filter", "(", "array", "$", "array", ",", "callable", "$", "callable", "=", "NULL", ")", "{", "$", "array", "=", "is_callable", "(", "$", "callable", ")", "?", "array_filter", "(", "$", "array", ",", "$", "callable", ")...
Filters a nested array recursively. @param array $array The filtered nested array. @param callable|null $callable The callable to apply for filtering. @return array The filtered array.
[ "Filters", "a", "nested", "array", "recursively", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Utility/NestedArray.php#L364-L373
train
drupal-code-builder/drupal-code-builder
Environment/Drush.php
Drush.getHooksDirectorySettingHelper
private function getHooksDirectorySettingHelper() { // Set the module folder based on variable. // First try the drush 'data' option. if (drush_get_option('data')) { $directory = drush_get_option('data'); if ($directory) { // In pure Drush, the hooks folder contains subfolder for hooks for // each major version of Drupal. if (substr($directory, -1, 1) != '/') { $directory .= '/'; } $directory .= $this->getCoreMajorVersion(); return $directory; } } // Second, use the config setting, in case we're in drush, but the site has // Module Builder running as a module. $directory = $this->getSetting('data_directory', 'hooks'); return $directory; }
php
private function getHooksDirectorySettingHelper() { // Set the module folder based on variable. // First try the drush 'data' option. if (drush_get_option('data')) { $directory = drush_get_option('data'); if ($directory) { // In pure Drush, the hooks folder contains subfolder for hooks for // each major version of Drupal. if (substr($directory, -1, 1) != '/') { $directory .= '/'; } $directory .= $this->getCoreMajorVersion(); return $directory; } } // Second, use the config setting, in case we're in drush, but the site has // Module Builder running as a module. $directory = $this->getSetting('data_directory', 'hooks'); return $directory; }
[ "private", "function", "getHooksDirectorySettingHelper", "(", ")", "{", "// Set the module folder based on variable.", "// First try the drush 'data' option.", "if", "(", "drush_get_option", "(", "'data'", ")", ")", "{", "$", "directory", "=", "drush_get_option", "(", "'dat...
Get the hooks directory. On Drush, this can come from several places, in the following order of preference: - The Drush --data option. This allows use of a central store of hook data that needs only be downloaded once for all Drupal sites. Subdirectories are made for each major version. - The Module Builder UI's variable. This will only be set if module builder has been installed as a Drupal module on the current site.
[ "Get", "the", "hooks", "directory", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Environment/Drush.php#L35-L54
train
drupal-code-builder/drupal-code-builder
Task/Collect/AdminRoutesCollector.php
AdminRoutesCollector.collect
public function collect($job_list) { $route_provider = \Drupal::service('router.route_provider'); // TODO: figure out how on earth getRoutesByPattern() is meant to work! $routes = $route_provider->getAllRoutes(); $admin_routes = []; foreach ($routes as $route_name => $route) { $controller = $route->getDefault('_controller'); if ($controller == '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage') { $route_path = $route->getPath(); // Skip the '/admin' path, as you don't put items there. if ($route_path == '/admin') { continue; } $admin_routes[$route_name] = [ 'route_name' => $route_name, 'path' => $route_path, 'title' => $route->getDefault('_title'), ]; } } return $admin_routes; }
php
public function collect($job_list) { $route_provider = \Drupal::service('router.route_provider'); // TODO: figure out how on earth getRoutesByPattern() is meant to work! $routes = $route_provider->getAllRoutes(); $admin_routes = []; foreach ($routes as $route_name => $route) { $controller = $route->getDefault('_controller'); if ($controller == '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage') { $route_path = $route->getPath(); // Skip the '/admin' path, as you don't put items there. if ($route_path == '/admin') { continue; } $admin_routes[$route_name] = [ 'route_name' => $route_name, 'path' => $route_path, 'title' => $route->getDefault('_title'), ]; } } return $admin_routes; }
[ "public", "function", "collect", "(", "$", "job_list", ")", "{", "$", "route_provider", "=", "\\", "Drupal", "::", "service", "(", "'router.route_provider'", ")", ";", "// TODO: figure out how on earth getRoutesByPattern() is meant to work!", "$", "routes", "=", "$", ...
Gets definitions of admin routes that show submenu blocks. @return array An array whose keys are the route names, and whose values are arrays containing: - 'route_name': The route name. - 'path': The path. - 'title': The route title.
[ "Gets", "definitions", "of", "admin", "routes", "that", "show", "submenu", "blocks", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/AdminRoutesCollector.php#L41-L66
train
drupal-code-builder/drupal-code-builder
Generator/Render/ClassAnnotation.php
ClassAnnotation.render
public function render($nesting = 0, $annotation_nesting = 0) { $docblock_lines = []; $indent = str_repeat(' ', $nesting); // Simple string annotation. if (is_string($this->data)) { // Quote the value. $value = '"' . $this->data . '"'; // If this is the top-level annotation, then the whole thing is a single // line and there is no terminal comma. $docblock_lines[] = "@{$this->annotationClassName}({$value})" . ($nesting ? ',' : ''); } else { // First line for the annotation key / class. $docblock_lines[] = "@{$this->annotationClassName}("; // Render the array of data recursively, including any nested annotations. $this->renderArray($docblock_lines, $this->data, $nesting + 1, $annotation_nesting); $docblock_lines[] = $indent . ")" . ($nesting ? ',' : ''); } return $docblock_lines; }
php
public function render($nesting = 0, $annotation_nesting = 0) { $docblock_lines = []; $indent = str_repeat(' ', $nesting); // Simple string annotation. if (is_string($this->data)) { // Quote the value. $value = '"' . $this->data . '"'; // If this is the top-level annotation, then the whole thing is a single // line and there is no terminal comma. $docblock_lines[] = "@{$this->annotationClassName}({$value})" . ($nesting ? ',' : ''); } else { // First line for the annotation key / class. $docblock_lines[] = "@{$this->annotationClassName}("; // Render the array of data recursively, including any nested annotations. $this->renderArray($docblock_lines, $this->data, $nesting + 1, $annotation_nesting); $docblock_lines[] = $indent . ")" . ($nesting ? ',' : ''); } return $docblock_lines; }
[ "public", "function", "render", "(", "$", "nesting", "=", "0", ",", "$", "annotation_nesting", "=", "0", ")", "{", "$", "docblock_lines", "=", "[", "]", ";", "$", "indent", "=", "str_repeat", "(", "' '", ",", "$", "nesting", ")", ";", "// Simple strin...
Renders the annotation as text lines without docblock formatting. @param int $nesting (optional) Internal. The current nesting level of the overal data. @param int $annotation_nesting (optional) Internal. The current nesting level in the current annotation. @return string[] The rendered lines of code.
[ "Renders", "the", "annotation", "as", "text", "lines", "without", "docblock", "formatting", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Render/ClassAnnotation.php#L97-L122
train
drupal-code-builder/drupal-code-builder
Generator/Render/ClassAnnotation.php
ClassAnnotation.renderArray
protected function renderArray(&$docblock_lines, $data, $nesting = 0, $annotation_nesting = 0) { $indent = str_repeat(' ', $nesting); foreach ($data as $key => $value) { if (is_numeric($key)) { // Numeric keys are not shown. $declaration_line = "{$indent}"; } else { // Keys need to be quoted for all levels except the first level of an // annotation. if ($annotation_nesting != 0) { $key = '"' . $key . '"'; } $declaration_line = "{$indent}{$key} = "; } if (is_string($value)) { $value = '"' . $value . '"'; $declaration_line .= "{$value},"; $docblock_lines[] = $declaration_line; } elseif (is_object($value)) { // Child annotation. The nesting level doesn't increase here, as the // child annotation class is just on the same line as the key. // The annotation nesting level is reset, as we are starting a new // annotation. $sub_lines = $value->render($nesting, 0); $declaration_line .= array_shift($sub_lines); $docblock_lines[] = $declaration_line; $docblock_lines = array_merge($docblock_lines, $sub_lines); } else { // Array of values. Recurse into this method. $declaration_line .= '{'; $docblock_lines[] = $declaration_line; $this->renderArray($docblock_lines, $value, $nesting + 1, $annotation_nesting + 1); $docblock_lines[] = $indent . "},"; } } }
php
protected function renderArray(&$docblock_lines, $data, $nesting = 0, $annotation_nesting = 0) { $indent = str_repeat(' ', $nesting); foreach ($data as $key => $value) { if (is_numeric($key)) { // Numeric keys are not shown. $declaration_line = "{$indent}"; } else { // Keys need to be quoted for all levels except the first level of an // annotation. if ($annotation_nesting != 0) { $key = '"' . $key . '"'; } $declaration_line = "{$indent}{$key} = "; } if (is_string($value)) { $value = '"' . $value . '"'; $declaration_line .= "{$value},"; $docblock_lines[] = $declaration_line; } elseif (is_object($value)) { // Child annotation. The nesting level doesn't increase here, as the // child annotation class is just on the same line as the key. // The annotation nesting level is reset, as we are starting a new // annotation. $sub_lines = $value->render($nesting, 0); $declaration_line .= array_shift($sub_lines); $docblock_lines[] = $declaration_line; $docblock_lines = array_merge($docblock_lines, $sub_lines); } else { // Array of values. Recurse into this method. $declaration_line .= '{'; $docblock_lines[] = $declaration_line; $this->renderArray($docblock_lines, $value, $nesting + 1, $annotation_nesting + 1); $docblock_lines[] = $indent . "},"; } } }
[ "protected", "function", "renderArray", "(", "&", "$", "docblock_lines", ",", "$", "data", ",", "$", "nesting", "=", "0", ",", "$", "annotation_nesting", "=", "0", ")", "{", "$", "indent", "=", "str_repeat", "(", "' '", ",", "$", "nesting", ")", ";", ...
Add lines for an array of data. @param string[] &$docblock_lines The lines of code assembled so far. Further lines are added to this. @param mixed $data The array of data. @param int $nesting (optional) See render(). @param int $annotation_nesting (optional) See render().
[ "Add", "lines", "for", "an", "array", "of", "data", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Render/ClassAnnotation.php#L136-L183
train
drupal-code-builder/drupal-code-builder
Task/ReportSummary.php
ReportSummary.listStoredData
public function listStoredData() { $return = []; // Hooks. $task_report_hooks = \DrupalCodeBuilder\Factory::getTask('ReportHookData'); $data = $task_report_hooks->listHookData(); $item = [ 'label' => 'Hooks', ]; $list = []; $count = 0; foreach ($data as $file => $hooks) { $list_group = []; foreach ($hooks as $key => $hook) { $list_group[$hook['name']] = $hook['description']; } $count += count($hooks); $list["Group $file:"] = $list_group; } $item['list'] = $list; $item['count'] = $count; $return['hooks'] = $item; // Services $task_report_service_data = \DrupalCodeBuilder\Factory::getTask('ReportServiceData'); $data = $task_report_service_data->listServiceNamesOptionsAll(); $return['services'] = [ 'label' => 'Services', 'list' => $data, 'count' => count($data), ]; // Tagged service types. $data = $task_report_service_data->listServiceTypeData(); $list = []; foreach ($data as $tag => $item) { $list[$tag] = $item['label']; } $return['tags'] = [ 'label' => 'Service tag types', 'list' => $list, 'count' => count($data), ]; // Plugin types. $task = \DrupalCodeBuilder\Factory::getTask('ReportPluginData'); $data = $task->listPluginNamesOptions(); $return['plugins'] = [ 'label' => 'Plugin types', 'list' => $data, 'count' => count($data), ]; // Field types. $task = \DrupalCodeBuilder\Factory::getTask('ReportFieldTypes'); $data = $task->listFieldTypesOptions(); $list = []; foreach ($data as $key => $label) { $list[$key] = $label; } $return['fields'] = [ 'label' => 'Field types', 'list' => $task->listFieldTypesOptions(), 'count' => count($data), ]; // Admin routes. $task = \DrupalCodeBuilder\Factory::getTask('ReportAdminRoutes'); $data = $task->listAdminRoutesOptions(); $return['admin_routes'] = [ 'label' => 'Admin routes', 'list' => $data, 'count' => count($data), ]; return $return; }
php
public function listStoredData() { $return = []; // Hooks. $task_report_hooks = \DrupalCodeBuilder\Factory::getTask('ReportHookData'); $data = $task_report_hooks->listHookData(); $item = [ 'label' => 'Hooks', ]; $list = []; $count = 0; foreach ($data as $file => $hooks) { $list_group = []; foreach ($hooks as $key => $hook) { $list_group[$hook['name']] = $hook['description']; } $count += count($hooks); $list["Group $file:"] = $list_group; } $item['list'] = $list; $item['count'] = $count; $return['hooks'] = $item; // Services $task_report_service_data = \DrupalCodeBuilder\Factory::getTask('ReportServiceData'); $data = $task_report_service_data->listServiceNamesOptionsAll(); $return['services'] = [ 'label' => 'Services', 'list' => $data, 'count' => count($data), ]; // Tagged service types. $data = $task_report_service_data->listServiceTypeData(); $list = []; foreach ($data as $tag => $item) { $list[$tag] = $item['label']; } $return['tags'] = [ 'label' => 'Service tag types', 'list' => $list, 'count' => count($data), ]; // Plugin types. $task = \DrupalCodeBuilder\Factory::getTask('ReportPluginData'); $data = $task->listPluginNamesOptions(); $return['plugins'] = [ 'label' => 'Plugin types', 'list' => $data, 'count' => count($data), ]; // Field types. $task = \DrupalCodeBuilder\Factory::getTask('ReportFieldTypes'); $data = $task->listFieldTypesOptions(); $list = []; foreach ($data as $key => $label) { $list[$key] = $label; } $return['fields'] = [ 'label' => 'Field types', 'list' => $task->listFieldTypesOptions(), 'count' => count($data), ]; // Admin routes. $task = \DrupalCodeBuilder\Factory::getTask('ReportAdminRoutes'); $data = $task->listAdminRoutesOptions(); $return['admin_routes'] = [ 'label' => 'Admin routes', 'list' => $data, 'count' => count($data), ]; return $return; }
[ "public", "function", "listStoredData", "(", ")", "{", "$", "return", "=", "[", "]", ";", "// Hooks.", "$", "task_report_hooks", "=", "\\", "DrupalCodeBuilder", "\\", "Factory", "::", "getTask", "(", "'ReportHookData'", ")", ";", "$", "data", "=", "$", "ta...
Returns a listing of all stored data, with counts. @return An array whose keys are short identifiers for the types of data, where each value is itself an array with: - 'label': A title case label for the type of data, e.g. 'Hooks'. - 'count': The number of stored definitions of this type. - 'list': A list of all the items. This is in the same format as Drupal FormAPI options, i.e. either: - an array of machine keys and label values. - a nested array where keys are group labels, and values are keys and labels as in the non-nested format.
[ "Returns", "a", "listing", "of", "all", "stored", "data", "with", "counts", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportSummary.php#L32-L117
train
drupal-code-builder/drupal-code-builder
Generator/EntityTypeBase.php
EntityTypeBase.getAnnotationData
protected function getAnnotationData() { $annotation_data = [ 'id' => $this->component_data['entity_type_id'], 'label' => ClassAnnotation::Translation($this->component_data['entity_type_label']), 'label_collection' => ClassAnnotation::Translation($this->component_data['entity_type_label'] . 's'), 'label_singular' => ClassAnnotation::Translation(strtolower($this->component_data['entity_type_label'])), 'label_plural' => ClassAnnotation::Translation(strtolower($this->component_data['entity_type_label']) . 's'), 'label_count' => ClassAnnotation::PluralTranslation([ 'singular' => "@count " . strtolower($this->component_data['entity_type_label']), 'plural' => "@count " . strtolower($this->component_data['entity_type_label']) . 's', ]), 'entity_keys' => $this->component_data['entity_keys'], ]; // Handlers. $handler_data = []; // Keep track of all the handler classes in a flat array keyed by the type // key so we don't have to work with the nested array for references to // other handlers. $handler_classes = []; foreach (static::getHandlerTypes() as $key => $handler_type_info) { $data_key = "handler_{$key}"; // Skip if nothing in the data. if (empty($this->component_data[$data_key])) { continue; } // Strict comparison, as could be TRUE. if ($this->component_data[$data_key] === 'none') { continue; } $option_value = $this->component_data[$data_key]; switch ($handler_type_info['mode']) { case 'core_default': // The FALSE case has been eliminated already, so must be TRUE. $handler_class = $this->makeQualifiedHandlerClassName($key, $handler_type_info); break; case 'core_none': if ($option_value == 'core') { $handler_class = substr($handler_type_info['base_class'], 1); } elseif ($option_value == 'custom') { $handler_class = $this->makeQualifiedHandlerClassName($key, $handler_type_info); } else { // Another option, specific to the handler type. $handler_class = substr($handler_type_info['options_classes'][$option_value], 1); } break; case 'custom_default': if ($option_value == 'default') { // Use a handler that's from another type. $handler_class = $handler_classes[$handler_type_info['default_type']]; } else { $handler_class = $this->makeQualifiedHandlerClassName($key, $handler_type_info); } break; } $handler_classes[$key] = $handler_class; if (isset($handler_type_info['property_path'])) { NestedArray::setValue($handler_data, $handler_type_info['property_path'], $handler_class); } else { $handler_data[$key] = $handler_class; } } if ($handler_data) { $annotation_data['handlers'] = $handler_data; } if ($this->component_data['admin_permission_name']) { $annotation_data['admin_permission'] = $this->component_data['admin_permission_name']; } return $annotation_data; }
php
protected function getAnnotationData() { $annotation_data = [ 'id' => $this->component_data['entity_type_id'], 'label' => ClassAnnotation::Translation($this->component_data['entity_type_label']), 'label_collection' => ClassAnnotation::Translation($this->component_data['entity_type_label'] . 's'), 'label_singular' => ClassAnnotation::Translation(strtolower($this->component_data['entity_type_label'])), 'label_plural' => ClassAnnotation::Translation(strtolower($this->component_data['entity_type_label']) . 's'), 'label_count' => ClassAnnotation::PluralTranslation([ 'singular' => "@count " . strtolower($this->component_data['entity_type_label']), 'plural' => "@count " . strtolower($this->component_data['entity_type_label']) . 's', ]), 'entity_keys' => $this->component_data['entity_keys'], ]; // Handlers. $handler_data = []; // Keep track of all the handler classes in a flat array keyed by the type // key so we don't have to work with the nested array for references to // other handlers. $handler_classes = []; foreach (static::getHandlerTypes() as $key => $handler_type_info) { $data_key = "handler_{$key}"; // Skip if nothing in the data. if (empty($this->component_data[$data_key])) { continue; } // Strict comparison, as could be TRUE. if ($this->component_data[$data_key] === 'none') { continue; } $option_value = $this->component_data[$data_key]; switch ($handler_type_info['mode']) { case 'core_default': // The FALSE case has been eliminated already, so must be TRUE. $handler_class = $this->makeQualifiedHandlerClassName($key, $handler_type_info); break; case 'core_none': if ($option_value == 'core') { $handler_class = substr($handler_type_info['base_class'], 1); } elseif ($option_value == 'custom') { $handler_class = $this->makeQualifiedHandlerClassName($key, $handler_type_info); } else { // Another option, specific to the handler type. $handler_class = substr($handler_type_info['options_classes'][$option_value], 1); } break; case 'custom_default': if ($option_value == 'default') { // Use a handler that's from another type. $handler_class = $handler_classes[$handler_type_info['default_type']]; } else { $handler_class = $this->makeQualifiedHandlerClassName($key, $handler_type_info); } break; } $handler_classes[$key] = $handler_class; if (isset($handler_type_info['property_path'])) { NestedArray::setValue($handler_data, $handler_type_info['property_path'], $handler_class); } else { $handler_data[$key] = $handler_class; } } if ($handler_data) { $annotation_data['handlers'] = $handler_data; } if ($this->component_data['admin_permission_name']) { $annotation_data['admin_permission'] = $this->component_data['admin_permission_name']; } return $annotation_data; }
[ "protected", "function", "getAnnotationData", "(", ")", "{", "$", "annotation_data", "=", "[", "'id'", "=>", "$", "this", "->", "component_data", "[", "'entity_type_id'", "]", ",", "'label'", "=>", "ClassAnnotation", "::", "Translation", "(", "$", "this", "->"...
Gets the data for the annotation. @return array A data array suitable for passing to ClassAnnotation.
[ "Gets", "the", "data", "for", "the", "annotation", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/EntityTypeBase.php#L535-L618
train
drupal-code-builder/drupal-code-builder
Generator/EntityTypeBase.php
EntityTypeBase.makeShortHandlerClassName
protected function makeShortHandlerClassName($handler_type_key, $handler_type_info) { if (isset($handler_type_info['class_name_suffix'])) { $short_class_name = $this->component_data['entity_class_name'] . $handler_type_info['class_name_suffix']; } else { $short_class_name = $this->component_data['entity_class_name'] . CaseString::snake($handler_type_key)->pascal(); } return $short_class_name; }
php
protected function makeShortHandlerClassName($handler_type_key, $handler_type_info) { if (isset($handler_type_info['class_name_suffix'])) { $short_class_name = $this->component_data['entity_class_name'] . $handler_type_info['class_name_suffix']; } else { $short_class_name = $this->component_data['entity_class_name'] . CaseString::snake($handler_type_key)->pascal(); } return $short_class_name; }
[ "protected", "function", "makeShortHandlerClassName", "(", "$", "handler_type_key", ",", "$", "handler_type_info", ")", "{", "if", "(", "isset", "(", "$", "handler_type_info", "[", "'class_name_suffix'", "]", ")", ")", "{", "$", "short_class_name", "=", "$", "th...
Helper to create the short class name for a handler. @param string $key The handler type key as defined by getHandlerTypes(). @param array $handler_type_info The handler type info as defined by getHandlerTypes(). @return string The fully-qualified handler class name.
[ "Helper", "to", "create", "the", "short", "class", "name", "for", "a", "handler", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/EntityTypeBase.php#L631-L640
train
drupal-code-builder/drupal-code-builder
Generator/EntityTypeBase.php
EntityTypeBase.getRelativeHandlerClassNamePieces
protected function getRelativeHandlerClassNamePieces($handler_type_key, $handler_type_info) { $handler_short_class_name = $this->makeShortHandlerClassName($handler_type_key, $handler_type_info); if (isset($handler_type_info['class_namespace'])) { $handler_relative_class_name = $handler_type_info['class_namespace']; $handler_relative_class_name[] = $handler_short_class_name; } else { $handler_relative_class_name = [ 'Entity', 'Handler', $handler_short_class_name, ]; } return $handler_relative_class_name; }
php
protected function getRelativeHandlerClassNamePieces($handler_type_key, $handler_type_info) { $handler_short_class_name = $this->makeShortHandlerClassName($handler_type_key, $handler_type_info); if (isset($handler_type_info['class_namespace'])) { $handler_relative_class_name = $handler_type_info['class_namespace']; $handler_relative_class_name[] = $handler_short_class_name; } else { $handler_relative_class_name = [ 'Entity', 'Handler', $handler_short_class_name, ]; } return $handler_relative_class_name; }
[ "protected", "function", "getRelativeHandlerClassNamePieces", "(", "$", "handler_type_key", ",", "$", "handler_type_info", ")", "{", "$", "handler_short_class_name", "=", "$", "this", "->", "makeShortHandlerClassName", "(", "$", "handler_type_key", ",", "$", "handler_ty...
Helper to create the relative namespaced class name for a handler. @param string $key The handler type key as defined by getHandlerTypes(). @param array $handler_type_info The handler type info as defined by getHandlerTypes(). @return string[] The handler class name, qualified relative to the module, as an array of name pieces.
[ "Helper", "to", "create", "the", "relative", "namespaced", "class", "name", "for", "a", "handler", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/EntityTypeBase.php#L654-L669
train
drupal-code-builder/drupal-code-builder
Generator/EntityTypeBase.php
EntityTypeBase.makeQualifiedHandlerClassName
protected function makeQualifiedHandlerClassName($handler_type_key, $handler_type_info) { $relative_name_pieces = $this->getRelativeHandlerClassNamePieces($handler_type_key, $handler_type_info); $name_pieces = array_merge([ 'Drupal', '%module', ], $relative_name_pieces); $handler_class_name = static::makeQualifiedClassName($name_pieces); return $handler_class_name; }
php
protected function makeQualifiedHandlerClassName($handler_type_key, $handler_type_info) { $relative_name_pieces = $this->getRelativeHandlerClassNamePieces($handler_type_key, $handler_type_info); $name_pieces = array_merge([ 'Drupal', '%module', ], $relative_name_pieces); $handler_class_name = static::makeQualifiedClassName($name_pieces); return $handler_class_name; }
[ "protected", "function", "makeQualifiedHandlerClassName", "(", "$", "handler_type_key", ",", "$", "handler_type_info", ")", "{", "$", "relative_name_pieces", "=", "$", "this", "->", "getRelativeHandlerClassNamePieces", "(", "$", "handler_type_key", ",", "$", "handler_ty...
Helper to create the full class name for a handler. @param string $key The handler type key as defined by getHandlerTypes(). @param array $handler_type_info The handler type info as defined by getHandlerTypes(). @return string The fully-qualified handler class name.
[ "Helper", "to", "create", "the", "full", "class", "name", "for", "a", "handler", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/EntityTypeBase.php#L682-L693
train
drupal-code-builder/drupal-code-builder
Task/Collect/HooksCollector7.php
HooksCollector7.getHookDestinations
private function getHookDestinations(&$hook_files) { // Get our data. $data = $this->getHookInfo(); // Incoming data is destination key, array of hooks. // (Because it makes typing the data out easier! Computers can just adapt.) foreach ($data as $module => $module_data) { // The key in $hook_files we correspond to // @todo, possibly: this feels like slightly shaky ground. $filename = "$module.api.php"; // Skip filenames we haven't already found, so we don't pollute our data // array with hook destination data for files that don't exist here. if (!isset($hook_files[$filename])) { continue; } // The module data can set a single destination for all its hooks. if (isset($module_data['destination'])) { $hook_files[$filename]['destination'] = $module_data['destination']; } // It can also (or instead) set a destination per hook. if (isset($module_data['hook_destinations'])) { $hook_files[$filename]['hook_destinations'] = array(); foreach ($module_data['hook_destinations'] as $destination => $hooks) { $destinations[$module] = array_fill_keys($hooks, $destination); $hook_files[$filename]['hook_destinations'] += array_fill_keys($hooks, $destination); } } // Add the dependencies array as it comes; it will be processed per hook later. if (isset($module_data['hook_dependencies'])) { $hook_files[$filename]['hook_dependencies'] = $module_data['hook_dependencies']; } } //print_r($hook_files); }
php
private function getHookDestinations(&$hook_files) { // Get our data. $data = $this->getHookInfo(); // Incoming data is destination key, array of hooks. // (Because it makes typing the data out easier! Computers can just adapt.) foreach ($data as $module => $module_data) { // The key in $hook_files we correspond to // @todo, possibly: this feels like slightly shaky ground. $filename = "$module.api.php"; // Skip filenames we haven't already found, so we don't pollute our data // array with hook destination data for files that don't exist here. if (!isset($hook_files[$filename])) { continue; } // The module data can set a single destination for all its hooks. if (isset($module_data['destination'])) { $hook_files[$filename]['destination'] = $module_data['destination']; } // It can also (or instead) set a destination per hook. if (isset($module_data['hook_destinations'])) { $hook_files[$filename]['hook_destinations'] = array(); foreach ($module_data['hook_destinations'] as $destination => $hooks) { $destinations[$module] = array_fill_keys($hooks, $destination); $hook_files[$filename]['hook_destinations'] += array_fill_keys($hooks, $destination); } } // Add the dependencies array as it comes; it will be processed per hook later. if (isset($module_data['hook_dependencies'])) { $hook_files[$filename]['hook_dependencies'] = $module_data['hook_dependencies']; } } //print_r($hook_files); }
[ "private", "function", "getHookDestinations", "(", "&", "$", "hook_files", ")", "{", "// Get our data.", "$", "data", "=", "$", "this", "->", "getHookInfo", "(", ")", ";", "// Incoming data is destination key, array of hooks.", "// (Because it makes typing the data out easi...
Add extra data about hook destinations to the hook file data. This allows entire files or individual hooks to have a file other than the default %module.module as their destination.
[ "Add", "extra", "data", "about", "hook", "destinations", "to", "the", "hook", "file", "data", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/HooksCollector7.php#L93-L130
train
drupal-code-builder/drupal-code-builder
Task/Collect/MethodCollector.php
MethodCollector.collectMethods
public function collectMethods($name) { // Get a reflection class for the interface. $reflection = new \ReflectionClass($name); $methods = $reflection->getMethods(); $data = []; foreach ($methods as $method) { // Dev trapdoor. if ($method->getName() != 'storageSettingsForm') { //continue; } $data[$method->getName()] = $this->getMethodData($method); } return $data; }
php
public function collectMethods($name) { // Get a reflection class for the interface. $reflection = new \ReflectionClass($name); $methods = $reflection->getMethods(); $data = []; foreach ($methods as $method) { // Dev trapdoor. if ($method->getName() != 'storageSettingsForm') { //continue; } $data[$method->getName()] = $this->getMethodData($method); } return $data; }
[ "public", "function", "collectMethods", "(", "$", "name", ")", "{", "// Get a reflection class for the interface.", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "name", ")", ";", "$", "methods", "=", "$", "reflection", "->", "getMethods", "(...
Get data for the methods of a class or interface. TODO: remove this, use getMethodData() from other classes. @param $name The fully-qualified name of the class or interface. @return An array keyed by method name, where each value is an array containing: - 'name: The name of the method. - 'declaration': The function declaration line. - 'description': The description from the method's docblock first line.
[ "Get", "data", "for", "the", "methods", "of", "a", "class", "or", "interface", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/MethodCollector.php#L28-L45
train
drupal-code-builder/drupal-code-builder
Task/Collect/MethodCollector.php
MethodCollector.getMethodData
public function getMethodData(\ReflectionMethod $method) { $interface_method_data = []; $interface_method_data['name'] = $method->getName(); // Methods may be in parent interfaces, so not all in the same file. $filename = $method->getFileName(); $source = file($filename); $start_line = $method->getStartLine(); // Trim whitespace from the front, as this will be indented. $interface_method_data['declaration'] = trim($source[$start_line - 1]); // Get the docblock for the method. $method_docblock_lines = explode("\n", $method->getDocComment()); foreach ($method_docblock_lines as $line) { // Take the first actual docblock line to be the description. // Need to use preg_match() rather than match exactly to account for $matches = []; if (preg_match('@^ +\* (.+)@', $line, $matches)) { $interface_method_data['description'] = $matches[1]; break; } } // Replace class typehints on method parameters with their full namespaced // versions, as typically these will be short class names. The PHPFile // generator will then take care of extracting namespaces and creating // import statements. // Get the typehint classes on parameters. $parameters = $method->getParameters(); $search = []; $replace = []; foreach ($parameters as $parameter) { $parameter_hinted_class = $parameter->getClass(); // Skip a parameter that doesn't have a class hint. if (is_null($parameter_hinted_class)) { continue; } // Create arrays for preg_replace() of search and replace strings. // Add a negative lookbehind for the backslash so we don't replace a // fully-qualified root-namespace typehint (such as \Iterator). // Add the space between the typehint and the parameter to help guard // against false replacements. $parameter_hinted_class_short_name = $parameter_hinted_class->getShortName(); $search[] = "@(?<!\\\\){$parameter_hinted_class_short_name}(?= )@"; // Prepend the initial '\'. $replace[] = '\\' . $parameter_hinted_class->getName(); } $interface_method_data['declaration'] = preg_replace( $search, $replace, $interface_method_data['declaration'] ); return $interface_method_data; }
php
public function getMethodData(\ReflectionMethod $method) { $interface_method_data = []; $interface_method_data['name'] = $method->getName(); // Methods may be in parent interfaces, so not all in the same file. $filename = $method->getFileName(); $source = file($filename); $start_line = $method->getStartLine(); // Trim whitespace from the front, as this will be indented. $interface_method_data['declaration'] = trim($source[$start_line - 1]); // Get the docblock for the method. $method_docblock_lines = explode("\n", $method->getDocComment()); foreach ($method_docblock_lines as $line) { // Take the first actual docblock line to be the description. // Need to use preg_match() rather than match exactly to account for $matches = []; if (preg_match('@^ +\* (.+)@', $line, $matches)) { $interface_method_data['description'] = $matches[1]; break; } } // Replace class typehints on method parameters with their full namespaced // versions, as typically these will be short class names. The PHPFile // generator will then take care of extracting namespaces and creating // import statements. // Get the typehint classes on parameters. $parameters = $method->getParameters(); $search = []; $replace = []; foreach ($parameters as $parameter) { $parameter_hinted_class = $parameter->getClass(); // Skip a parameter that doesn't have a class hint. if (is_null($parameter_hinted_class)) { continue; } // Create arrays for preg_replace() of search and replace strings. // Add a negative lookbehind for the backslash so we don't replace a // fully-qualified root-namespace typehint (such as \Iterator). // Add the space between the typehint and the parameter to help guard // against false replacements. $parameter_hinted_class_short_name = $parameter_hinted_class->getShortName(); $search[] = "@(?<!\\\\){$parameter_hinted_class_short_name}(?= )@"; // Prepend the initial '\'. $replace[] = '\\' . $parameter_hinted_class->getName(); } $interface_method_data['declaration'] = preg_replace( $search, $replace, $interface_method_data['declaration'] ); return $interface_method_data; }
[ "public", "function", "getMethodData", "(", "\\", "ReflectionMethod", "$", "method", ")", "{", "$", "interface_method_data", "=", "[", "]", ";", "$", "interface_method_data", "[", "'name'", "]", "=", "$", "method", "->", "getName", "(", ")", ";", "// Methods...
Gets data for a method. @param \ReflectionMethod $method The reflection object for the method. @return An array containing: - 'name: The name of the method. - 'declaration': The function declaration line. - 'description': The description from the method's docblock first line.
[ "Gets", "data", "for", "a", "method", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/MethodCollector.php#L59-L119
train
drupal-code-builder/drupal-code-builder
Environment/BaseEnvironment.php
BaseEnvironment.getHooksDirectorySetting
protected function getHooksDirectorySetting() { // Set the module folder based on variable. $directory = $this->getSetting('data_directory', 'hooks'); // Run it through version-specific stuff. // This basically prepends 'public://' or 'sites/default/files/'. $this->version_helper->directoryPath($directory); $this->hooks_directory = $directory; }
php
protected function getHooksDirectorySetting() { // Set the module folder based on variable. $directory = $this->getSetting('data_directory', 'hooks'); // Run it through version-specific stuff. // This basically prepends 'public://' or 'sites/default/files/'. $this->version_helper->directoryPath($directory); $this->hooks_directory = $directory; }
[ "protected", "function", "getHooksDirectorySetting", "(", ")", "{", "// Set the module folder based on variable.", "$", "directory", "=", "$", "this", "->", "getSetting", "(", "'data_directory'", ",", "'hooks'", ")", ";", "// Run it through version-specific stuff.", "// Thi...
Get the hooks directory setting from the environment and set it locally.
[ "Get", "the", "hooks", "directory", "setting", "from", "the", "environment", "and", "set", "it", "locally", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Environment/BaseEnvironment.php#L136-L145
train
drupal-code-builder/drupal-code-builder
Task/ReportPluginData.php
ReportPluginData.listPluginData
function listPluginData($discovery_type = NULL) { // We may come here several times, so cache this. // TODO: look into finer-grained caching higher up. static $cache; if (isset($cache[$discovery_type])) { return $cache[$discovery_type]; } $plugin_data = $this->environment->getStorage()->retrieve('plugins'); // Filter the plugins by the discovery type. if ($discovery_type) { $plugin_data = array_filter($plugin_data, function($item) use ($discovery_type) { $discovery_pieces = explode('\\', $item['discovery']); $discovery_short_name = array_pop($discovery_pieces); return ($discovery_short_name == $discovery_type); }); } $cache[$discovery_type] = $plugin_data; return $plugin_data; }
php
function listPluginData($discovery_type = NULL) { // We may come here several times, so cache this. // TODO: look into finer-grained caching higher up. static $cache; if (isset($cache[$discovery_type])) { return $cache[$discovery_type]; } $plugin_data = $this->environment->getStorage()->retrieve('plugins'); // Filter the plugins by the discovery type. if ($discovery_type) { $plugin_data = array_filter($plugin_data, function($item) use ($discovery_type) { $discovery_pieces = explode('\\', $item['discovery']); $discovery_short_name = array_pop($discovery_pieces); return ($discovery_short_name == $discovery_type); }); } $cache[$discovery_type] = $plugin_data; return $plugin_data; }
[ "function", "listPluginData", "(", "$", "discovery_type", "=", "NULL", ")", "{", "// We may come here several times, so cache this.", "// TODO: look into finer-grained caching higher up.", "static", "$", "cache", ";", "if", "(", "isset", "(", "$", "cache", "[", "$", "di...
Get the list of plugin data. @param $discovery_type (optional) The short name of a discovery class to limit the plugin list by. Possible values include: - AnnotatedClassDiscovery - YamlDiscovery @return The processed plugin data. @see \DrupalCodeBuilder\Task\Collect8::gatherPluginTypeInfo()
[ "Get", "the", "list", "of", "plugin", "data", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportPluginData.php#L37-L61
train
drupal-code-builder/drupal-code-builder
Task/ReportPluginData.php
ReportPluginData.listPluginDataBySubdirectory
public function listPluginDataBySubdirectory() { $plugin_types_data = $this->listPluginData('AnnotatedClassDiscovery'); $plugin_types_data_by_subdirectory = []; foreach ($plugin_types_data as $plugin_id => $plugin_definition) { if (!empty($plugin_definition['subdir'])) { $subdir = substr($plugin_definition['subdir'], strlen('Plugin/')); $plugin_types_data_by_subdirectory[$subdir] = $plugin_definition; } } return $plugin_types_data_by_subdirectory; }
php
public function listPluginDataBySubdirectory() { $plugin_types_data = $this->listPluginData('AnnotatedClassDiscovery'); $plugin_types_data_by_subdirectory = []; foreach ($plugin_types_data as $plugin_id => $plugin_definition) { if (!empty($plugin_definition['subdir'])) { $subdir = substr($plugin_definition['subdir'], strlen('Plugin/')); $plugin_types_data_by_subdirectory[$subdir] = $plugin_definition; } } return $plugin_types_data_by_subdirectory; }
[ "public", "function", "listPluginDataBySubdirectory", "(", ")", "{", "$", "plugin_types_data", "=", "$", "this", "->", "listPluginData", "(", "'AnnotatedClassDiscovery'", ")", ";", "$", "plugin_types_data_by_subdirectory", "=", "[", "]", ";", "foreach", "(", "$", ...
Returns a list of annotated plugin types, keyed by subdirectory. @return A list of all plugin types that use annotation discovery, keyed by the subdirectory the plugin files go in, for example, 'Block', 'QueueWorker'.
[ "Returns", "a", "list", "of", "annotated", "plugin", "types", "keyed", "by", "subdirectory", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportPluginData.php#L70-L81
train
drupal-code-builder/drupal-code-builder
Task/ReportPluginData.php
ReportPluginData.listPluginNamesOptions
function listPluginNamesOptions($discovery_type = NULL) { $data = $this->listPluginData($discovery_type); $return = array(); foreach ($data as $plugin_type_name => $plugin_type_info) { $return[$plugin_type_name] = $plugin_type_info['type_label']; } return $return; }
php
function listPluginNamesOptions($discovery_type = NULL) { $data = $this->listPluginData($discovery_type); $return = array(); foreach ($data as $plugin_type_name => $plugin_type_info) { $return[$plugin_type_name] = $plugin_type_info['type_label']; } return $return; }
[ "function", "listPluginNamesOptions", "(", "$", "discovery_type", "=", "NULL", ")", "{", "$", "data", "=", "$", "this", "->", "listPluginData", "(", "$", "discovery_type", ")", ";", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "$", "data",...
Get plugin types as a list of options. @param $discovery_type (optional) The short name of a discovery class to limit the plugin list @return An array of plugin types as options suitable for FormAPI.
[ "Get", "plugin", "types", "as", "a", "list", "of", "options", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportPluginData.php#L92-L101
train
drupal-code-builder/drupal-code-builder
Task/ReportFieldTypes.php
ReportFieldTypes.listFieldTypesOptions
public function listFieldTypesOptions() { $field_types_data = $this->loadFieldTypeData(); $return = []; foreach ($field_types_data as $field_type_id => $field_type_info) { $return[$field_type_id] = $field_type_info['label']; } return $return; }
php
public function listFieldTypesOptions() { $field_types_data = $this->loadFieldTypeData(); $return = []; foreach ($field_types_data as $field_type_id => $field_type_info) { $return[$field_type_id] = $field_type_info['label']; } return $return; }
[ "public", "function", "listFieldTypesOptions", "(", ")", "{", "$", "field_types_data", "=", "$", "this", "->", "loadFieldTypeData", "(", ")", ";", "$", "return", "=", "[", "]", ";", "foreach", "(", "$", "field_types_data", "as", "$", "field_type_id", "=>", ...
Get a list of options for field types. @return An array of field types as options suitable for FormAPI.
[ "Get", "a", "list", "of", "options", "for", "field", "types", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportFieldTypes.php#L31-L40
train
drupal-code-builder/drupal-code-builder
Task/ReportFieldTypes.php
ReportFieldTypes.loadFieldTypeData
protected function loadFieldTypeData() { if (!isset($this->fieldTypesData)) { $this->fieldTypesData = $this->environment->getStorage()->retrieve('field_types'); } return $this->fieldTypesData; }
php
protected function loadFieldTypeData() { if (!isset($this->fieldTypesData)) { $this->fieldTypesData = $this->environment->getStorage()->retrieve('field_types'); } return $this->fieldTypesData; }
[ "protected", "function", "loadFieldTypeData", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "fieldTypesData", ")", ")", "{", "$", "this", "->", "fieldTypesData", "=", "$", "this", "->", "environment", "->", "getStorage", "(", ")", "->",...
Loads the field type data from storage. @return The data array, as stored by the FieldTypesCollector.
[ "Loads", "the", "field", "type", "data", "from", "storage", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportFieldTypes.php#L48-L54
train
drupal-code-builder/drupal-code-builder
Generator/Info8.php
Info8.file_body
function file_body() { $args = func_get_args(); $files = array_shift($args); $module_data = $this->component_data; //print_r($module_data); $lines = array(); $lines['name'] = $module_data['readable_name']; $lines['type'] = $module_data['base']; $lines['description'] = $module_data['short_description']; if (!empty($module_data['module_dependencies'])) { // For lines which form a set with the same key and array markers, // simply make an array. foreach ($module_data['module_dependencies'] as $dependency) { $lines['dependencies'][] = $dependency; } } if (!empty($module_data['module_package'])) { $lines['package'] = $module_data['module_package']; } $lines['core'] = "8.x"; if (!empty($this->extraLines)) { $lines = array_merge($lines, $this->extraLines); } $info = $this->process_info_lines($lines); return $info; }
php
function file_body() { $args = func_get_args(); $files = array_shift($args); $module_data = $this->component_data; //print_r($module_data); $lines = array(); $lines['name'] = $module_data['readable_name']; $lines['type'] = $module_data['base']; $lines['description'] = $module_data['short_description']; if (!empty($module_data['module_dependencies'])) { // For lines which form a set with the same key and array markers, // simply make an array. foreach ($module_data['module_dependencies'] as $dependency) { $lines['dependencies'][] = $dependency; } } if (!empty($module_data['module_package'])) { $lines['package'] = $module_data['module_package']; } $lines['core'] = "8.x"; if (!empty($this->extraLines)) { $lines = array_merge($lines, $this->extraLines); } $info = $this->process_info_lines($lines); return $info; }
[ "function", "file_body", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "files", "=", "array_shift", "(", "$", "args", ")", ";", "$", "module_data", "=", "$", "this", "->", "component_data", ";", "//print_r($module_data);", "$", "l...
Create lines of file body for Drupal 8.
[ "Create", "lines", "of", "file", "body", "for", "Drupal", "8", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Info8.php#L51-L82
train
drupal-code-builder/drupal-code-builder
Task/ReportServiceData.php
ReportServiceData.listServiceNamesOptions
function listServiceNamesOptions() { $service_data = $this->loadServiceData(); $return = array(); foreach ($service_data['primary'] as $service_id => $service_info) { $return[$service_id] = $service_info['label']; } return $return; }
php
function listServiceNamesOptions() { $service_data = $this->loadServiceData(); $return = array(); foreach ($service_data['primary'] as $service_id => $service_info) { $return[$service_id] = $service_info['label']; } return $return; }
[ "function", "listServiceNamesOptions", "(", ")", "{", "$", "service_data", "=", "$", "this", "->", "loadServiceData", "(", ")", ";", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "$", "service_data", "[", "'primary'", "]", "as", "$", "servi...
Get a list of options of the major services. @return An array of Service types as options suitable for FormAPI.
[ "Get", "a", "list", "of", "options", "of", "the", "major", "services", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportServiceData.php#L38-L47
train
drupal-code-builder/drupal-code-builder
Task/ReportServiceData.php
ReportServiceData.listServiceNamesOptionsAll
public function listServiceNamesOptionsAll() { $service_data = $this->loadServiceData(); $return = array(); foreach ($service_data['all'] as $service_id => $service_info) { $return[$service_id] = $service_info['label']; } return $return; }
php
public function listServiceNamesOptionsAll() { $service_data = $this->loadServiceData(); $return = array(); foreach ($service_data['all'] as $service_id => $service_info) { $return[$service_id] = $service_info['label']; } return $return; }
[ "public", "function", "listServiceNamesOptionsAll", "(", ")", "{", "$", "service_data", "=", "$", "this", "->", "loadServiceData", "(", ")", ";", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "$", "service_data", "[", "'all'", "]", "as", "$...
Get a list of options of all the services. @return An array of Service types as options suitable for FormAPI.
[ "Get", "a", "list", "of", "options", "of", "all", "the", "services", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportServiceData.php#L55-L64
train
drupal-code-builder/drupal-code-builder
Task/ReportServiceData.php
ReportServiceData.listServiceTypeData
public function listServiceTypeData() { if (!isset($this->serviceTypesData)) { $this->serviceTypesData = $this->environment->getStorage()->retrieve('service_tag_types'); } return $this->serviceTypesData; }
php
public function listServiceTypeData() { if (!isset($this->serviceTypesData)) { $this->serviceTypesData = $this->environment->getStorage()->retrieve('service_tag_types'); } return $this->serviceTypesData; }
[ "public", "function", "listServiceTypeData", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "serviceTypesData", ")", ")", "{", "$", "this", "->", "serviceTypesData", "=", "$", "this", "->", "environment", "->", "getStorage", "(", ")", "-...
Get the list of Service types data. @return The processed Service types data.
[ "Get", "the", "list", "of", "Service", "types", "data", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportServiceData.php#L72-L77
train
drupal-code-builder/drupal-code-builder
Task/ReportServiceData.php
ReportServiceData.loadServiceData
protected function loadServiceData() { if (!isset($this->serviceData)) { $this->serviceData = $this->environment->getStorage()->retrieve('services'); } // Populate the keys, in case analysis crashed. $this->serviceData += [ 'primary' => [], 'all' => [], ]; return $this->serviceData; }
php
protected function loadServiceData() { if (!isset($this->serviceData)) { $this->serviceData = $this->environment->getStorage()->retrieve('services'); } // Populate the keys, in case analysis crashed. $this->serviceData += [ 'primary' => [], 'all' => [], ]; return $this->serviceData; }
[ "protected", "function", "loadServiceData", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "serviceData", ")", ")", "{", "$", "this", "->", "serviceData", "=", "$", "this", "->", "environment", "->", "getStorage", "(", ")", "->", "retr...
Loads the service data from storage. @return The data array, as stored by the ServicesCollector.
[ "Loads", "the", "service", "data", "from", "storage", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportServiceData.php#L85-L97
train
drupal-code-builder/drupal-code-builder
Task/Generate/ComponentPropertyPreparer.php
ComponentPropertyPreparer.prepareComponentDataPropertyCreateOptions
protected function prepareComponentDataPropertyCreateOptions($property_name, &$property_info) { if (isset($property_info['options'])) { $options_callback = $property_info['options']; // We may have prepared this options array from a callback previously, // when preparing multiple child items of a compound property. if (!is_callable($options_callback) && is_array($options_callback)) { return; } if (is_callable($options_callback)) { // The 'options' attribute is a callback that supplies the options // array. $options = $options_callback($property_info); } elseif (is_string($options_callback) && strpos($options_callback, ':') !== FALSE) { // The 'options' attribute is in the form 'TASKNAME:METHOD', to call to // get the options array. list($task_name, $method) = explode(':', $options_callback); $task_handler = \DrupalCodeBuilder\Factory::getTask($task_name); $options = call_user_func([$task_handler, $method]); } else { // The 'options' attribute format is incorrect. throw new \Exception("Unable to prepare options for property $property_name."); } $property_info['options'] = $options; } // Extract options from a list of presets for the property. if (isset($property_info['presets'])) { $options = []; foreach ($property_info['presets'] as $key => $preset_info) { $options[$key] = $preset_info['label']; } $property_info['options'] = $options; } // Recurse child properties. if (isset($property_info['properties'])) { foreach ($property_info['properties'] as $child_property_name => &$child_property_info) { $this->prepareComponentDataPropertyCreateOptions($child_property_name, $child_property_info); } } }
php
protected function prepareComponentDataPropertyCreateOptions($property_name, &$property_info) { if (isset($property_info['options'])) { $options_callback = $property_info['options']; // We may have prepared this options array from a callback previously, // when preparing multiple child items of a compound property. if (!is_callable($options_callback) && is_array($options_callback)) { return; } if (is_callable($options_callback)) { // The 'options' attribute is a callback that supplies the options // array. $options = $options_callback($property_info); } elseif (is_string($options_callback) && strpos($options_callback, ':') !== FALSE) { // The 'options' attribute is in the form 'TASKNAME:METHOD', to call to // get the options array. list($task_name, $method) = explode(':', $options_callback); $task_handler = \DrupalCodeBuilder\Factory::getTask($task_name); $options = call_user_func([$task_handler, $method]); } else { // The 'options' attribute format is incorrect. throw new \Exception("Unable to prepare options for property $property_name."); } $property_info['options'] = $options; } // Extract options from a list of presets for the property. if (isset($property_info['presets'])) { $options = []; foreach ($property_info['presets'] as $key => $preset_info) { $options[$key] = $preset_info['label']; } $property_info['options'] = $options; } // Recurse child properties. if (isset($property_info['properties'])) { foreach ($property_info['properties'] as $child_property_name => &$child_property_info) { $this->prepareComponentDataPropertyCreateOptions($child_property_name, $child_property_info); } } }
[ "protected", "function", "prepareComponentDataPropertyCreateOptions", "(", "$", "property_name", ",", "&", "$", "property_info", ")", "{", "if", "(", "isset", "(", "$", "property_info", "[", "'options'", "]", ")", ")", "{", "$", "options_callback", "=", "$", "...
Creates the options array for a property. An options array may be in the info array, or generated in one of the following ways: - The property info's 'options' key is a callback, which returns the array of options. - The property info's has a 'presets' key, whose items are converted to the options. @param $property_name The name of the property. @param &$property_info The property into array, passed by reference.
[ "Creates", "the", "options", "array", "for", "a", "property", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Generate/ComponentPropertyPreparer.php#L41-L88
train
drupal-code-builder/drupal-code-builder
Generator/PHPFile.php
PHPFile.code_header
function code_header() { $lines = array( "@file", $this->fileDocblockSummary(), ); $code = $this->docBlock($lines); // Blank line after the file docblock. $code[] = ''; return $code; }
php
function code_header() { $lines = array( "@file", $this->fileDocblockSummary(), ); $code = $this->docBlock($lines); // Blank line after the file docblock. $code[] = ''; return $code; }
[ "function", "code_header", "(", ")", "{", "$", "lines", "=", "array", "(", "\"@file\"", ",", "$", "this", "->", "fileDocblockSummary", "(", ")", ",", ")", ";", "$", "code", "=", "$", "this", "->", "docBlock", "(", "$", "lines", ")", ";", "// Blank li...
Return the file doxygen header and any custom header code.
[ "Return", "the", "file", "doxygen", "header", "and", "any", "custom", "header", "code", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/PHPFile.php#L82-L91
train
drupal-code-builder/drupal-code-builder
Generator/PHPFile.php
PHPFile.extractFullyQualifiedClasses
protected function extractFullyQualifiedClasses(&$class_code, &$imported_classes, $current_namespace = '') { $current_namespace_pieces = explode('\\', $current_namespace); foreach ($class_code as &$line) { // Skip lines which are part of a comment block. if (preg_match('@^\s*\*@', $line)) { continue; } // Skip lines which are a single comment. if (preg_match('@^\s*//@', $line)) { continue; } // Skip PHPStorm variable typehints. if (preg_match('@^\s*/\*\*@', $line)) { continue; } $matches = []; // Do not match after a ' or ", as then the class name is a quoted string // and should be left alone. // Do not match after a letter, as then that's also part of the namespace // and we shouldn't be matching only the tail end. // Allow a match of '%module' for a namespace piece, for cases where we // refer to something we are also in the process of generating, e.g. a // plugin base class referencing a plugin interface. if (preg_match_all('@(?<![\'"[:alpha:]])(?:\\\\(\w+|%module)){2,}@', $line, $matches, PREG_SET_ORDER)) { foreach ($matches as $match_set) { $fully_qualified_class_name = $match_set[0]; $class_name = $match_set[1]; $line = preg_replace('@' . preg_quote($fully_qualified_class_name) . '@', $class_name, $line); $fully_qualified_class_name = ltrim($fully_qualified_class_name, '\\'); $namespace_pieces = array_slice(explode('\\', $fully_qualified_class_name), 0, -1); if ($namespace_pieces != $current_namespace_pieces) { $imported_classes[] = ltrim($fully_qualified_class_name, '\\'); } } } } // Remove duplicates. $imported_classes = array_unique($imported_classes); }
php
protected function extractFullyQualifiedClasses(&$class_code, &$imported_classes, $current_namespace = '') { $current_namespace_pieces = explode('\\', $current_namespace); foreach ($class_code as &$line) { // Skip lines which are part of a comment block. if (preg_match('@^\s*\*@', $line)) { continue; } // Skip lines which are a single comment. if (preg_match('@^\s*//@', $line)) { continue; } // Skip PHPStorm variable typehints. if (preg_match('@^\s*/\*\*@', $line)) { continue; } $matches = []; // Do not match after a ' or ", as then the class name is a quoted string // and should be left alone. // Do not match after a letter, as then that's also part of the namespace // and we shouldn't be matching only the tail end. // Allow a match of '%module' for a namespace piece, for cases where we // refer to something we are also in the process of generating, e.g. a // plugin base class referencing a plugin interface. if (preg_match_all('@(?<![\'"[:alpha:]])(?:\\\\(\w+|%module)){2,}@', $line, $matches, PREG_SET_ORDER)) { foreach ($matches as $match_set) { $fully_qualified_class_name = $match_set[0]; $class_name = $match_set[1]; $line = preg_replace('@' . preg_quote($fully_qualified_class_name) . '@', $class_name, $line); $fully_qualified_class_name = ltrim($fully_qualified_class_name, '\\'); $namespace_pieces = array_slice(explode('\\', $fully_qualified_class_name), 0, -1); if ($namespace_pieces != $current_namespace_pieces) { $imported_classes[] = ltrim($fully_qualified_class_name, '\\'); } } } } // Remove duplicates. $imported_classes = array_unique($imported_classes); }
[ "protected", "function", "extractFullyQualifiedClasses", "(", "&", "$", "class_code", ",", "&", "$", "imported_classes", ",", "$", "current_namespace", "=", "''", ")", "{", "$", "current_namespace_pieces", "=", "explode", "(", "'\\\\'", ",", "$", "current_namespac...
Remove fully-qualified classnames, extracting them to an array. @param &$class_code An array of PHP code lines to work on. All namespaced classes will be replaced with plain classes. @param &$imported_classes An array to populate with the fully-qualified classnames which are removed. These are without the initial namespace separator. @param string $current_namespace (optional) The namespace of the current file, without the initial '\'. If omitted, no comparison of namespace is done.
[ "Remove", "fully", "-", "qualified", "classnames", "extracting", "them", "to", "an", "array", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/PHPFile.php#L142-L185
train
drupal-code-builder/drupal-code-builder
Generator/PHPFile.php
PHPFile.imports
function imports($imported_classes = []) { $imports = []; if ($imported_classes) { // Sort the imported classes. sort($imported_classes); foreach ($imported_classes as $fully_qualified_class_name) { $fully_qualified_class_name = ltrim($fully_qualified_class_name, '\\'); $imports[] = "use $fully_qualified_class_name;"; } $imports[] = ''; } return $imports; }
php
function imports($imported_classes = []) { $imports = []; if ($imported_classes) { // Sort the imported classes. sort($imported_classes); foreach ($imported_classes as $fully_qualified_class_name) { $fully_qualified_class_name = ltrim($fully_qualified_class_name, '\\'); $imports[] = "use $fully_qualified_class_name;"; } $imports[] = ''; } return $imports; }
[ "function", "imports", "(", "$", "imported_classes", "=", "[", "]", ")", "{", "$", "imports", "=", "[", "]", ";", "if", "(", "$", "imported_classes", ")", "{", "// Sort the imported classes.", "sort", "(", "$", "imported_classes", ")", ";", "foreach", "(",...
Produces the namespace import statements. @param $imported_classes (optional) An array of fully-qualified class names.
[ "Produces", "the", "namespace", "import", "statements", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/PHPFile.php#L193-L209
train
drupal-code-builder/drupal-code-builder
Task/Collect/HooksCollector6.php
HooksCollector6.getHookFileUrls
function getHookFileUrls($directory) { // Get our data. $data = $this->getHookInfo(); foreach ($data as $module => $module_data) { $branch = $module_data['branch']; foreach ($module_data['hook_files'] as $hook_file => $destination) { $url = str_replace( array('%file', '%branch'), array($hook_file, $branch), $module_data['url'] ); // Create our own safe filename with module prefix. $hook_file_safe_name = "$module.$hook_file"; $urls[$hook_file_safe_name]['path'] = $directory . '/' . $hook_file_safe_name; $urls[$hook_file_safe_name]['url'] = $url; $urls[$hook_file_safe_name]['destination'] = $destination; if (isset($module_data['hook_destinations'])) { $urls[$hook_file_safe_name]['hook_destinations'] = array(); foreach ($module_data['hook_destinations'] as $destination => $hooks) { $urls[$hook_file_safe_name]['hook_destinations'] += array_fill_keys($hooks, $destination); } } if ($module_data['group'] == '#filenames') { $urls[$hook_file_safe_name]['group'] = str_replace('.php', '', $hook_file); } else { $urls[$hook_file_safe_name]['group'] = $module_data['group']; } } } //print_r($urls); return $urls; }
php
function getHookFileUrls($directory) { // Get our data. $data = $this->getHookInfo(); foreach ($data as $module => $module_data) { $branch = $module_data['branch']; foreach ($module_data['hook_files'] as $hook_file => $destination) { $url = str_replace( array('%file', '%branch'), array($hook_file, $branch), $module_data['url'] ); // Create our own safe filename with module prefix. $hook_file_safe_name = "$module.$hook_file"; $urls[$hook_file_safe_name]['path'] = $directory . '/' . $hook_file_safe_name; $urls[$hook_file_safe_name]['url'] = $url; $urls[$hook_file_safe_name]['destination'] = $destination; if (isset($module_data['hook_destinations'])) { $urls[$hook_file_safe_name]['hook_destinations'] = array(); foreach ($module_data['hook_destinations'] as $destination => $hooks) { $urls[$hook_file_safe_name]['hook_destinations'] += array_fill_keys($hooks, $destination); } } if ($module_data['group'] == '#filenames') { $urls[$hook_file_safe_name]['group'] = str_replace('.php', '', $hook_file); } else { $urls[$hook_file_safe_name]['group'] = $module_data['group']; } } } //print_r($urls); return $urls; }
[ "function", "getHookFileUrls", "(", "$", "directory", ")", "{", "// Get our data.", "$", "data", "=", "$", "this", "->", "getHookInfo", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "module", "=>", "$", "module_data", ")", "{", "$", "branch", ...
Get list of hook file URLS from any modules that declare them. @param $directory The path to the module builder hooks directory. @return An array of data about the files to download, keyed by (safe) filename: [system.core.php] => Array [path] => the full path this file should be saved to [url] => URL [destination] => %module.module [group] => core
[ "Get", "list", "of", "hook", "file", "URLS", "from", "any", "modules", "that", "declare", "them", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/HooksCollector6.php#L61-L96
train
drupal-code-builder/drupal-code-builder
Utility/CodeAnalysis/DependencyInjection.php
DependencyInjection.getInjectedParameters
public static function getInjectedParameters($class, $fixed_parameter_count) { if (!method_exists($class, '__construct')) { return []; } if (!method_exists($class, 'create')) { return []; } // Get the parameter data for the __construct() method from the reflection // helper. $construct_R = new Method($class, '__construct'); $parameter_data = $construct_R->getParamData(); $injection_parameter_data = array_slice($parameter_data, $fixed_parameter_count); // Extract code from the call to 'new Class()' from the body of the // create() method. $create_R = new Method($class, 'create'); $create_method_body = $create_R->getBody(); $matches = []; preg_match('@ new \s+ static \( ( [^;]+ ) \) ; @x', $create_method_body, $matches); // Bail if we didn't find the call. if (empty($matches[1])) { // TODO: some classes call parent::create()! return []; } $parameters = explode(',', $matches[1]); $create_container_extractions = []; foreach (array_slice($parameters, 3) as $i => $parameter) { $injection_parameter_data[$i]['extraction'] = trim($parameter); } return $injection_parameter_data; }
php
public static function getInjectedParameters($class, $fixed_parameter_count) { if (!method_exists($class, '__construct')) { return []; } if (!method_exists($class, 'create')) { return []; } // Get the parameter data for the __construct() method from the reflection // helper. $construct_R = new Method($class, '__construct'); $parameter_data = $construct_R->getParamData(); $injection_parameter_data = array_slice($parameter_data, $fixed_parameter_count); // Extract code from the call to 'new Class()' from the body of the // create() method. $create_R = new Method($class, 'create'); $create_method_body = $create_R->getBody(); $matches = []; preg_match('@ new \s+ static \( ( [^;]+ ) \) ; @x', $create_method_body, $matches); // Bail if we didn't find the call. if (empty($matches[1])) { // TODO: some classes call parent::create()! return []; } $parameters = explode(',', $matches[1]); $create_container_extractions = []; foreach (array_slice($parameters, 3) as $i => $parameter) { $injection_parameter_data[$i]['extraction'] = trim($parameter); } return $injection_parameter_data; }
[ "public", "static", "function", "getInjectedParameters", "(", "$", "class", ",", "$", "fixed_parameter_count", ")", "{", "if", "(", "!", "method_exists", "(", "$", "class", ",", "'__construct'", ")", ")", "{", "return", "[", "]", ";", "}", "if", "(", "!"...
Gets data on the parameters injected into the class constructor. @param string $class The class name. @param int $fixed_parameter_count The number of fixed parameters which are independent of dependency injection. These are the parameters which get passed to __construct() @return An numeric array where each item is data for a parameter, containing: - 'type': The typehint for the parameter. - 'name': The name of the parameter without the leading '$'. - 'extraction': The code snippet used in the create() method to extract the service from the container.
[ "Gets", "data", "on", "the", "parameters", "injected", "into", "the", "class", "constructor", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Utility/CodeAnalysis/DependencyInjection.php#L27-L64
train
drupal-code-builder/drupal-code-builder
Generator/Collection/ComponentCollection.php
ComponentCollection.addComponent
public function addComponent($local_name, BaseGenerator $component, $requesting_component) { // Components may not be added once the collection is locked. if ($this->locked) { throw new \LogicException("Attempt to add component to locked collection."); } $key = $this->getComponentKey($component); if (isset($this->components[$key])) { throw new \Exception("Unique ID $key already in use, by component with request path {$this->requestPaths[$key]}."); } // If this is the first component, it's the root. if (!isset($this->rootGeneratorId)) { $this->rootGeneratorId = $key; $request_path = 'root'; // Create the first item in the request paths array. $this->requestPaths[$key] = $request_path; } // If this is *a* root, keep track of it. if ($component instanceof \DrupalCodeBuilder\Generator\RootComponent) { $this->roots[$key] = TRUE; } if ($requesting_component) { $request_path = $this->requestPaths[$this->getComponentKey($requesting_component)] . '/' . $local_name; // Add to the array of request paths. $this->requestPaths[$key] = $request_path; // Add to the array of requesters. if (!isset($this->requesters[$key])) { // TODO: store multiple requesters? $this->requesters[$key] = $this->getComponentKey($requesting_component); } // Keep track of the nearest requesting root component. $closest_requesting_root = $this->determineNearestRequestingRoot($key); $this->requestRoots[$key] = $closest_requesting_root; // Add to the array of local names. $this->localNames[$this->getComponentKey($requesting_component)][$local_name] = $key; } // Add to the merge tags list. if ($merge_tag = $component->getMergeTag()) { // $closest_requesting_root will be set because the root component has // no merge tag. $this->mergeTags[$closest_requesting_root][$component->getType()][$component->getMergeTag()] = $key; } $this->components[$key] = $component; }
php
public function addComponent($local_name, BaseGenerator $component, $requesting_component) { // Components may not be added once the collection is locked. if ($this->locked) { throw new \LogicException("Attempt to add component to locked collection."); } $key = $this->getComponentKey($component); if (isset($this->components[$key])) { throw new \Exception("Unique ID $key already in use, by component with request path {$this->requestPaths[$key]}."); } // If this is the first component, it's the root. if (!isset($this->rootGeneratorId)) { $this->rootGeneratorId = $key; $request_path = 'root'; // Create the first item in the request paths array. $this->requestPaths[$key] = $request_path; } // If this is *a* root, keep track of it. if ($component instanceof \DrupalCodeBuilder\Generator\RootComponent) { $this->roots[$key] = TRUE; } if ($requesting_component) { $request_path = $this->requestPaths[$this->getComponentKey($requesting_component)] . '/' . $local_name; // Add to the array of request paths. $this->requestPaths[$key] = $request_path; // Add to the array of requesters. if (!isset($this->requesters[$key])) { // TODO: store multiple requesters? $this->requesters[$key] = $this->getComponentKey($requesting_component); } // Keep track of the nearest requesting root component. $closest_requesting_root = $this->determineNearestRequestingRoot($key); $this->requestRoots[$key] = $closest_requesting_root; // Add to the array of local names. $this->localNames[$this->getComponentKey($requesting_component)][$local_name] = $key; } // Add to the merge tags list. if ($merge_tag = $component->getMergeTag()) { // $closest_requesting_root will be set because the root component has // no merge tag. $this->mergeTags[$closest_requesting_root][$component->getType()][$component->getMergeTag()] = $key; } $this->components[$key] = $component; }
[ "public", "function", "addComponent", "(", "$", "local_name", ",", "BaseGenerator", "$", "component", ",", "$", "requesting_component", ")", "{", "// Components may not be added once the collection is locked.", "if", "(", "$", "this", "->", "locked", ")", "{", "throw"...
Adds a component to the collection. @param $local_name The local name for the component, that is, the name used within the requesting components list of components to spawn, whether from properties or from requests. @param $component The component to add. @param $requesting_component The component that requested the component being added. May be NULL if the component being added is the root component.
[ "Adds", "a", "component", "to", "the", "collection", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Collection/ComponentCollection.php#L162-L217
train
drupal-code-builder/drupal-code-builder
Generator/Collection/ComponentCollection.php
ComponentCollection.addAliasedComponent
public function addAliasedComponent($local_name, BaseGenerator $existing_component, BaseGenerator $requesting_component) { $this->localNames[$this->getComponentKey($requesting_component)][$local_name] = $this->getComponentKey($existing_component); }
php
public function addAliasedComponent($local_name, BaseGenerator $existing_component, BaseGenerator $requesting_component) { $this->localNames[$this->getComponentKey($requesting_component)][$local_name] = $this->getComponentKey($existing_component); }
[ "public", "function", "addAliasedComponent", "(", "$", "local_name", ",", "BaseGenerator", "$", "existing_component", ",", "BaseGenerator", "$", "requesting_component", ")", "{", "$", "this", "->", "localNames", "[", "$", "this", "->", "getComponentKey", "(", "$",...
Add details for a component's that's been replaced by an existing one. This ensures that the local names array still has track of the requested local name, even though the request didn't result in a new component. @param $local_name The local name for the component that is being discarded, that is, the name used within the requesting components list of components to spawn, whether from properties or from requests. @param $existing_component The existing component which caused the new component to be discarded. @param $requesting_component The component that requested the new component being discarded.
[ "Add", "details", "for", "a", "component", "s", "that", "s", "been", "replaced", "by", "an", "existing", "one", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Collection/ComponentCollection.php#L234-L236
train
drupal-code-builder/drupal-code-builder
Generator/Collection/ComponentCollection.php
ComponentCollection.determineNearestRequestingRoot
private function determineNearestRequestingRoot($key) { // We're ascending a tree whose root is a root component, so we have to // find a root eventually. // Note that the nearest requesting root of a root component is not itself. // E.g. with this chain: // root -> requested -> inner_root // the nearest root of inner_root is root. do { $key = $this->requesters[$key]; } while (!isset($this->roots[$key])); return $key; }
php
private function determineNearestRequestingRoot($key) { // We're ascending a tree whose root is a root component, so we have to // find a root eventually. // Note that the nearest requesting root of a root component is not itself. // E.g. with this chain: // root -> requested -> inner_root // the nearest root of inner_root is root. do { $key = $this->requesters[$key]; } while (!isset($this->roots[$key])); return $key; }
[ "private", "function", "determineNearestRequestingRoot", "(", "$", "key", ")", "{", "// We're ascending a tree whose root is a root component, so we have to", "// find a root eventually.", "// Note that the nearest requesting root of a root component is not itself.", "// E.g. with this chain:"...
Determines the closest requester that is a root component. @param $key The ID of the component. @return The ID of the closest component in the request chain that is a root component.
[ "Determines", "the", "closest", "requester", "that", "is", "a", "root", "component", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Collection/ComponentCollection.php#L248-L261
train
drupal-code-builder/drupal-code-builder
Generator/Collection/ComponentCollection.php
ComponentCollection.getContainmentTreeWithRequestPaths
public function getContainmentTreeWithRequestPaths() { $tree_by_path = []; $tree = $this->getContainmentTree(); foreach ($tree as $parent => $children) { foreach ($children as $child) { $tree_by_path[$this->requestPaths[$parent]][] = $this->requestPaths[$child]; } } return $tree_by_path; }
php
public function getContainmentTreeWithRequestPaths() { $tree_by_path = []; $tree = $this->getContainmentTree(); foreach ($tree as $parent => $children) { foreach ($children as $child) { $tree_by_path[$this->requestPaths[$parent]][] = $this->requestPaths[$child]; } } return $tree_by_path; }
[ "public", "function", "getContainmentTreeWithRequestPaths", "(", ")", "{", "$", "tree_by_path", "=", "[", "]", ";", "$", "tree", "=", "$", "this", "->", "getContainmentTree", "(", ")", ";", "foreach", "(", "$", "tree", "as", "$", "parent", "=>", "$", "ch...
Gets the containment tree, with components represented by request paths. @return array An array of the same structure as getContainmentTree() returns, but instead of using object keys, every component is represented by its request path.
[ "Gets", "the", "containment", "tree", "with", "components", "represented", "by", "request", "paths", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Collection/ComponentCollection.php#L437-L449
train
drupal-code-builder/drupal-code-builder
Generator/Collection/ComponentCollection.php
ComponentCollection.getContainmentTreeChildren
public function getContainmentTreeChildren(BaseGenerator $component) { $component_id = $this->getComponentKey($component); $tree = $this->getContainmentTree(); $child_ids = $tree[$component_id] ?? []; $return = []; foreach ($child_ids as $id) { $return[$id] = $this->components[$id]; } return $return; }
php
public function getContainmentTreeChildren(BaseGenerator $component) { $component_id = $this->getComponentKey($component); $tree = $this->getContainmentTree(); $child_ids = $tree[$component_id] ?? []; $return = []; foreach ($child_ids as $id) { $return[$id] = $this->components[$id]; } return $return; }
[ "public", "function", "getContainmentTreeChildren", "(", "BaseGenerator", "$", "component", ")", "{", "$", "component_id", "=", "$", "this", "->", "getComponentKey", "(", "$", "component", ")", ";", "$", "tree", "=", "$", "this", "->", "getContainmentTree", "(...
Gets a component's children in the tree. @param BaseGenerator $component The component to get children for. @return BaseGenerator[] The child components, keyed by unique ID.
[ "Gets", "a", "component", "s", "children", "in", "the", "tree", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Collection/ComponentCollection.php#L460-L472
train
drupal-code-builder/drupal-code-builder
Generator/Collection/ComponentCollection.php
ComponentCollection.getMatchingComponent
public function getMatchingComponent($component, $requesting_component) { if (is_null($requesting_component)) { return; } if (!$component->getMergeTag()) { return NULL; } // We've not added $component yet (and might not), so we don't know have // any data about it. So we need to use the requesting component to get the // closest requesting root. $requesting_component_id = $this->getComponentKey($requesting_component); if (isset($this->roots[$requesting_component_id])) { // If the requesting component is a root, it's obviously the closest // requesting root. But getClosestRequestingRootComponent() would not // give us this, as root's closest requester is not itself. $closest_requesting_root_id = $requesting_component_id; } else { $closest_requesting_root_id = $this->getComponentKey($this->getClosestRequestingRootComponent($requesting_component)); } if (isset($this->mergeTags[$closest_requesting_root_id][$component->getType()][$component->getMergeTag()])) { $matching_component_id = $this->mergeTags[$closest_requesting_root_id][$component->getType()][$component->getMergeTag()]; return $this->components[$matching_component_id]; } }
php
public function getMatchingComponent($component, $requesting_component) { if (is_null($requesting_component)) { return; } if (!$component->getMergeTag()) { return NULL; } // We've not added $component yet (and might not), so we don't know have // any data about it. So we need to use the requesting component to get the // closest requesting root. $requesting_component_id = $this->getComponentKey($requesting_component); if (isset($this->roots[$requesting_component_id])) { // If the requesting component is a root, it's obviously the closest // requesting root. But getClosestRequestingRootComponent() would not // give us this, as root's closest requester is not itself. $closest_requesting_root_id = $requesting_component_id; } else { $closest_requesting_root_id = $this->getComponentKey($this->getClosestRequestingRootComponent($requesting_component)); } if (isset($this->mergeTags[$closest_requesting_root_id][$component->getType()][$component->getMergeTag()])) { $matching_component_id = $this->mergeTags[$closest_requesting_root_id][$component->getType()][$component->getMergeTag()]; return $this->components[$matching_component_id]; } }
[ "public", "function", "getMatchingComponent", "(", "$", "component", ",", "$", "requesting_component", ")", "{", "if", "(", "is_null", "(", "$", "requesting_component", ")", ")", "{", "return", ";", "}", "if", "(", "!", "$", "component", "->", "getMergeTag",...
Get the component that matches the type and merge tag, if any. @param $component The component to find a match for, not yet in the collection. @param $requesting_component The component that is requesting the component to match. @return Either a component that's in the collection and matches the given component, or NULL if nothing was found.
[ "Get", "the", "component", "that", "matches", "the", "type", "and", "merge", "tag", "if", "any", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Collection/ComponentCollection.php#L505-L532
train
drupal-code-builder/drupal-code-builder
Generator/Collection/ComponentCollection.php
ComponentCollection.getClosestRequestingRootComponent
public function getClosestRequestingRootComponent(BaseGenerator $component) { if ($this->getComponentKey($component) === $this->rootGeneratorId) { throw new \LogicException("ComponentCollection::getClosestRequestingRootComponent() may not be called with the root component."); } $component_id = $this->getComponentKey($component); $closest_requesting_root_id = $this->requestRoots[$component_id]; return $this->components[$closest_requesting_root_id]; }
php
public function getClosestRequestingRootComponent(BaseGenerator $component) { if ($this->getComponentKey($component) === $this->rootGeneratorId) { throw new \LogicException("ComponentCollection::getClosestRequestingRootComponent() may not be called with the root component."); } $component_id = $this->getComponentKey($component); $closest_requesting_root_id = $this->requestRoots[$component_id]; return $this->components[$closest_requesting_root_id]; }
[ "public", "function", "getClosestRequestingRootComponent", "(", "BaseGenerator", "$", "component", ")", "{", "if", "(", "$", "this", "->", "getComponentKey", "(", "$", "component", ")", "===", "$", "this", "->", "rootGeneratorId", ")", "{", "throw", "new", "\\...
Returns the closest requester that is a root component. This may be called before the collection is complete. @param BaseGenerator $component The component to get children for. @return The root component. @throws \LogicException Throws an exception if called with the root component, as in that case the answer does not make sense.
[ "Returns", "the", "closest", "requester", "that", "is", "a", "root", "component", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Collection/ComponentCollection.php#L549-L558
train
drupal-code-builder/drupal-code-builder
Generator/Collection/ComponentCollection.php
ComponentCollection.dumpStructure
private function dumpStructure() { dump("Requesters:"); dump($this->requesters); dump("Request roots:"); dump($this->requestRoots); dump("Request paths:"); dump($this->requestPaths); dump("Local names:"); dump($this->localNames); if (isset($this->tree)) { dump("Containment tree:"); dump($this->tree); } }
php
private function dumpStructure() { dump("Requesters:"); dump($this->requesters); dump("Request roots:"); dump($this->requestRoots); dump("Request paths:"); dump($this->requestPaths); dump("Local names:"); dump($this->localNames); if (isset($this->tree)) { dump("Containment tree:"); dump($this->tree); } }
[ "private", "function", "dumpStructure", "(", ")", "{", "dump", "(", "\"Requesters:\"", ")", ";", "dump", "(", "$", "this", "->", "requesters", ")", ";", "dump", "(", "\"Request roots:\"", ")", ";", "dump", "(", "$", "this", "->", "requestRoots", ")", ";"...
Dumps the data structures of the collection for debugging.
[ "Dumps", "the", "data", "structures", "of", "the", "collection", "for", "debugging", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Collection/ComponentCollection.php#L563-L580
train
drupal-code-builder/drupal-code-builder
Task/Collect/HooksCollector.php
HooksCollector.collect
public function collect($job_list) { $hook_files = $this->gatherHookDocumentationFiles($job_list); // Copy the hook files to the hooks directory. // This is done after the files have been gathered, so when gathering // sample data for tests the filtered files only are written. foreach ($hook_files as $file_info) { copy($file_info['original'], $file_info['path']); } // Process the hook files into a single array for storage. $processed_hook_data = $this->processHookData($hook_files); return $processed_hook_data; }
php
public function collect($job_list) { $hook_files = $this->gatherHookDocumentationFiles($job_list); // Copy the hook files to the hooks directory. // This is done after the files have been gathered, so when gathering // sample data for tests the filtered files only are written. foreach ($hook_files as $file_info) { copy($file_info['original'], $file_info['path']); } // Process the hook files into a single array for storage. $processed_hook_data = $this->processHookData($hook_files); return $processed_hook_data; }
[ "public", "function", "collect", "(", "$", "job_list", ")", "{", "$", "hook_files", "=", "$", "this", "->", "gatherHookDocumentationFiles", "(", "$", "job_list", ")", ";", "// Copy the hook files to the hooks directory.", "// This is done after the files have been gathered,...
Get definitions of hooks. @param $job_list The data returned from getJobList(). @return array An array of data about hooks.
[ "Get", "definitions", "of", "hooks", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/HooksCollector.php#L57-L71
train
drupal-code-builder/drupal-code-builder
Task/Collect/HooksCollector.php
HooksCollector.processHookData
protected function processHookData($hook_file_data) { //print_r($hook_file_data); // check file_exists? /* // Developer trapdoor for generating the sample hook definitions file for // our tests. This limits the number of files to just a few from core. $intersect = array( 'system.api.php', 'node.api.php', ); $hook_file_data = array_intersect_key($hook_file_data, array_fill_keys($intersect, TRUE)); // End. */ // Get hook_hook_info() from Drupal. $hook_info = $this->getDrupalHookInfo(); // Build list of hooks $hook_groups = array(); foreach ($hook_file_data as $file_data) { $hook_data_raw = $this->processHookFile($file_data['path']); $file_name = basename($file_data['path'], '.php'); $group = $file_data['group']; // Create an array in the form of: // array( // 'filename' => array( // array('hook' => 'hook_foo', 'description' => 'hook_foo description'), // ... // ), // ... // ); foreach ($hook_data_raw['names'] as $key => $hook) { // The destination is possibly specified per-hook; if not, then given // for the whole file. if (isset($file_data['hook_destinations'][$hook])) { $destination = $file_data['hook_destinations'][$hook]; } else { $destination = $file_data['destination']; } // Also try to get destinations from hook_hook_info(). // Argh why don't we have the short name here yet???? // @todo: clean up! $short_name = substr($hook, 5); if (isset($hook_info[$short_name])) { //print_r($hook_info); $destination = '%module.' . $hook_info[$short_name]['group'] . '.inc'; } // Process hook dependendies for the file. $hook_dependencies = array(); if (isset($file_data['hook_dependencies'])) { // Incoming data is of the form: // 'required hook' => array('dependent hooks') // where the latter may be a regexp. foreach ($file_data['hook_dependencies'] as $required_hook => $dependency_data) { foreach ($dependency_data as $match) { if (preg_match("@$match@", $hook)) { $hook_dependencies[] = $required_hook; } } } } // See if the hook has any callbacks as dependencies. We assume that // mention of a string of the form 'callback_foo()' means it's needed // for the hook. // TODO: see if there's a way to label this in the resulting source // as associated with the hook that requested this. $matches = array(); preg_match_all("@(callback_\w+)\(\)@", $hook_data_raw['documentation'][$key], $matches); if (!empty($matches[1])) { $hook_dependencies += $matches[1]; } // Because we're working through the raw data array, we keep the incoming // sort order. // But if there are multiple hook files for one module / group, then // they will go sequentially one after the other. // TODO: should this be improved, eg to group also by filename? $hook_groups[$group][$hook] = array( 'type' => $hook_data_raw['type'][$key], 'name' => $hook, 'definition' => $hook_data_raw['definitions'][$key], 'description' => $hook_data_raw['descriptions'][$key], // Don't store this!! TODO!! just use it for callback dependencies!!! //'documentation' => $hook_data_raw['documentation'][$key], 'destination' => $destination, 'dependencies' => $hook_dependencies, 'group' => $group, 'core' => $file_data['core'] ?? NULL, 'file_path' => $file_data['path'], 'body' => $hook_data_raw['bodies'][$key], ); //dsm($hook_groups); //drush_print_r($hook_groups); } // foreach hook_data } // foreach files //dsm($hook_groups); //print_r($hook_groups); return $hook_groups; }
php
protected function processHookData($hook_file_data) { //print_r($hook_file_data); // check file_exists? /* // Developer trapdoor for generating the sample hook definitions file for // our tests. This limits the number of files to just a few from core. $intersect = array( 'system.api.php', 'node.api.php', ); $hook_file_data = array_intersect_key($hook_file_data, array_fill_keys($intersect, TRUE)); // End. */ // Get hook_hook_info() from Drupal. $hook_info = $this->getDrupalHookInfo(); // Build list of hooks $hook_groups = array(); foreach ($hook_file_data as $file_data) { $hook_data_raw = $this->processHookFile($file_data['path']); $file_name = basename($file_data['path'], '.php'); $group = $file_data['group']; // Create an array in the form of: // array( // 'filename' => array( // array('hook' => 'hook_foo', 'description' => 'hook_foo description'), // ... // ), // ... // ); foreach ($hook_data_raw['names'] as $key => $hook) { // The destination is possibly specified per-hook; if not, then given // for the whole file. if (isset($file_data['hook_destinations'][$hook])) { $destination = $file_data['hook_destinations'][$hook]; } else { $destination = $file_data['destination']; } // Also try to get destinations from hook_hook_info(). // Argh why don't we have the short name here yet???? // @todo: clean up! $short_name = substr($hook, 5); if (isset($hook_info[$short_name])) { //print_r($hook_info); $destination = '%module.' . $hook_info[$short_name]['group'] . '.inc'; } // Process hook dependendies for the file. $hook_dependencies = array(); if (isset($file_data['hook_dependencies'])) { // Incoming data is of the form: // 'required hook' => array('dependent hooks') // where the latter may be a regexp. foreach ($file_data['hook_dependencies'] as $required_hook => $dependency_data) { foreach ($dependency_data as $match) { if (preg_match("@$match@", $hook)) { $hook_dependencies[] = $required_hook; } } } } // See if the hook has any callbacks as dependencies. We assume that // mention of a string of the form 'callback_foo()' means it's needed // for the hook. // TODO: see if there's a way to label this in the resulting source // as associated with the hook that requested this. $matches = array(); preg_match_all("@(callback_\w+)\(\)@", $hook_data_raw['documentation'][$key], $matches); if (!empty($matches[1])) { $hook_dependencies += $matches[1]; } // Because we're working through the raw data array, we keep the incoming // sort order. // But if there are multiple hook files for one module / group, then // they will go sequentially one after the other. // TODO: should this be improved, eg to group also by filename? $hook_groups[$group][$hook] = array( 'type' => $hook_data_raw['type'][$key], 'name' => $hook, 'definition' => $hook_data_raw['definitions'][$key], 'description' => $hook_data_raw['descriptions'][$key], // Don't store this!! TODO!! just use it for callback dependencies!!! //'documentation' => $hook_data_raw['documentation'][$key], 'destination' => $destination, 'dependencies' => $hook_dependencies, 'group' => $group, 'core' => $file_data['core'] ?? NULL, 'file_path' => $file_data['path'], 'body' => $hook_data_raw['bodies'][$key], ); //dsm($hook_groups); //drush_print_r($hook_groups); } // foreach hook_data } // foreach files //dsm($hook_groups); //print_r($hook_groups); return $hook_groups; }
[ "protected", "function", "processHookData", "(", "$", "hook_file_data", ")", "{", "//print_r($hook_file_data);", "// check file_exists?", "/*\n // Developer trapdoor for generating the sample hook definitions file for\n // our tests. This limits the number of files to just a few from core....
Builds complete hook data array from downloaded files and stores in a file. @param hook_file_data An array of data about the files to process: -[MODULE.FILENAME] => Array // eg system.core.php - [path] => full path to the file - [destination] => %module.module - [group] => GROUP // eg core - [hook_destinations] => array(%module.foo => hook_foo, etc) - [hook_dependencies] => array() This is the same format as returned by update.inc. @return An array keyed by originating file of the following form: [GROUP] => array( // grouping for UI. [hook_foo] => array( [name] => hook_foo [definition] => function hook_foo($node, $teaser = FALSE, $page = FALSE) [description] => Description. [destination] => Destination module file for hook code from this file. ... further properties: 'type' => $hook_data_raw['type'][$key], 'name' => $hook, 'definition' => $hook_data_raw['definitions'][$key], 'description' => $hook_data_raw['descriptions'][$key], TODO: Don't store this, just use it to figure out callback dependencies! 'documentation' => $hook_data_raw['documentation'][$key], 'destination' => $destination, 'dependencies' => $hook_dependencies, 'group' => $group, 'file_path' => $file_data['path'], 'body' => $hook_data_raw['bodies'][$key],
[ "Builds", "complete", "hook", "data", "array", "from", "downloaded", "files", "and", "stores", "in", "a", "file", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/HooksCollector.php#L166-L275
train
drupal-code-builder/drupal-code-builder
Task/Collect/HooksCollector.php
HooksCollector.processHookFile
protected function processHookFile($filepath) { $contents = file_get_contents("$filepath"); // Prepare a replacement set of the import statements, so we can replace // short class names will fully-qualified ones, so the sample code can // actually run. $imports_pattern = "@^use (.+);@m"; $matches = []; preg_match_all($imports_pattern, $contents, $matches); $imports = $matches[1]; $import_replacements = []; foreach ($imports as $import) { $pieces = explode('\\', $import); $short_class_name = array_pop($pieces); $import_replacements['@\b' . $short_class_name . '\b@'] = '\\' . $import; } // The pattern for extracting function data: capture first line of doc, // function declaration, and hook name. $pattern = '[ / \* \* \n # start phpdoc \ \* \ ( .* ) \n # first line of phpdoc: capture the text for the description ( (?: \ \* .* \n )* ) # lines of phpdoc: capture the documentation \ \* / \n # end phpdoc ( function \ ( ( hook | callback ) \w+ ) .* ) \ { # function declaration: capture... # ^ entire definition and name # ^ function name # ^ whether this is a hook or a callback ( (?: .* \n )*? ) # function body: capture example code ^ } ]mx'; $matches = []; preg_match_all($pattern, $contents, $matches); // We don't care about the full matches. //array_shift($matches); $data = array( 'descriptions' => $matches[1], 'documentation' => $matches[2], 'definitions' => $matches[3], 'names' => $matches[4], 'type' => $matches[5], 'bodies' => $matches[6], ); // Replace all the short class names in body code with fully-qualified ones. foreach ($data['bodies'] as &$hook_body) { $hook_body = preg_replace(array_keys($import_replacements), array_values($import_replacements), $hook_body); } return $data; }
php
protected function processHookFile($filepath) { $contents = file_get_contents("$filepath"); // Prepare a replacement set of the import statements, so we can replace // short class names will fully-qualified ones, so the sample code can // actually run. $imports_pattern = "@^use (.+);@m"; $matches = []; preg_match_all($imports_pattern, $contents, $matches); $imports = $matches[1]; $import_replacements = []; foreach ($imports as $import) { $pieces = explode('\\', $import); $short_class_name = array_pop($pieces); $import_replacements['@\b' . $short_class_name . '\b@'] = '\\' . $import; } // The pattern for extracting function data: capture first line of doc, // function declaration, and hook name. $pattern = '[ / \* \* \n # start phpdoc \ \* \ ( .* ) \n # first line of phpdoc: capture the text for the description ( (?: \ \* .* \n )* ) # lines of phpdoc: capture the documentation \ \* / \n # end phpdoc ( function \ ( ( hook | callback ) \w+ ) .* ) \ { # function declaration: capture... # ^ entire definition and name # ^ function name # ^ whether this is a hook or a callback ( (?: .* \n )*? ) # function body: capture example code ^ } ]mx'; $matches = []; preg_match_all($pattern, $contents, $matches); // We don't care about the full matches. //array_shift($matches); $data = array( 'descriptions' => $matches[1], 'documentation' => $matches[2], 'definitions' => $matches[3], 'names' => $matches[4], 'type' => $matches[5], 'bodies' => $matches[6], ); // Replace all the short class names in body code with fully-qualified ones. foreach ($data['bodies'] as &$hook_body) { $hook_body = preg_replace(array_keys($import_replacements), array_values($import_replacements), $hook_body); } return $data; }
[ "protected", "function", "processHookFile", "(", "$", "filepath", ")", "{", "$", "contents", "=", "file_get_contents", "(", "\"$filepath\"", ")", ";", "// Prepare a replacement set of the import statements, so we can replace", "// short class names will fully-qualified ones, so the...
Extracts raw hook data from a downloaded hook documentation file. @param string $filepath Path to hook file. @return array Array of hook data, in different arrays, where each array is keyed numerically and all the indexes match up. The arrays are: - 'type': Whether this is a hook or a callback. - 'descriptions': Each hook's user-friendly description, taken from the first line of the PHPdoc. - 'documentation': The rest of the PHPdoc. - 'definitions: Each hook's entire function declaration: "function name($params)" - 'names': The long names of the hooks, i.e. 'hook_foo'. - 'bodies': The function bodies of each hook.
[ "Extracts", "raw", "hook", "data", "from", "a", "downloaded", "hook", "documentation", "file", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/HooksCollector.php#L294-L349
train
drupal-code-builder/drupal-code-builder
Task/Collect/HooksCollector.php
HooksCollector.getHookInfo
protected function getHookInfo() { // Get data by invoking our hook. $data = \DrupalCodeBuilder\Factory::getEnvironment()->invokeInfoHook(); // Add our data. $result = $this->getAdditionalHookInfo(); $data = array_merge($data, $result); return $data; }
php
protected function getHookInfo() { // Get data by invoking our hook. $data = \DrupalCodeBuilder\Factory::getEnvironment()->invokeInfoHook(); // Add our data. $result = $this->getAdditionalHookInfo(); $data = array_merge($data, $result); return $data; }
[ "protected", "function", "getHookInfo", "(", ")", "{", "// Get data by invoking our hook.", "$", "data", "=", "\\", "DrupalCodeBuilder", "\\", "Factory", "::", "getEnvironment", "(", ")", "->", "invokeInfoHook", "(", ")", ";", "// Add our data.", "$", "result", "=...
Get hook information declared by Module Builder. This invokes our own hook, hook_module_builder_info(), as well as adding hardcoded info such as module file locations, which can't be deduced from either api.php files or hook_hook_info().
[ "Get", "hook", "information", "declared", "by", "Module", "Builder", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/HooksCollector.php#L371-L380
train
drupal-code-builder/drupal-code-builder
Generator/Render/FormAPIArrayRenderer.php
FormAPIArrayRenderer.getRecursiveIterator
protected function getRecursiveIterator() { $data_iterator = $this->getArrayIterator(); return new \RecursiveIteratorIterator( new \RecursiveCachingIterator($data_iterator, \CachingIterator::TOSTRING_USE_KEY), \RecursiveIteratorIterator::SELF_FIRST ); }
php
protected function getRecursiveIterator() { $data_iterator = $this->getArrayIterator(); return new \RecursiveIteratorIterator( new \RecursiveCachingIterator($data_iterator, \CachingIterator::TOSTRING_USE_KEY), \RecursiveIteratorIterator::SELF_FIRST ); }
[ "protected", "function", "getRecursiveIterator", "(", ")", "{", "$", "data_iterator", "=", "$", "this", "->", "getArrayIterator", "(", ")", ";", "return", "new", "\\", "RecursiveIteratorIterator", "(", "new", "\\", "RecursiveCachingIterator", "(", "$", "data_itera...
Gets the outer iterator object to use. @return \OuterIterator The iterator.
[ "Gets", "the", "outer", "iterator", "object", "to", "use", "." ]
7a9b9895218c729cd5f4c1dba75010f53c7da92e
https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Render/FormAPIArrayRenderer.php#L60-L67
train