code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
protected function getInspectorInstance($exception = null) { return new Inspector($exception); }
@param Exception $exception|null @return \Whoops\Exception\Inspector
getInspectorInstance
php
filp/whoops
tests/Whoops/Exception/InspectorTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Exception/InspectorTest.php
MIT
public function testExceptionIsStoredAndReturned() { $exception = $this->getException(); $inspector = $this->getInspectorInstance($exception); $this->assertSame($exception, $inspector->getException()); }
@covers Whoops\Exception\Inspector::__construct @covers Whoops\Exception\Inspector::getException
testExceptionIsStoredAndReturned
php
filp/whoops
tests/Whoops/Exception/InspectorTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Exception/InspectorTest.php
MIT
public function testPreviousException() { $previousException = $this->getException("I'm here first!"); $exception = $this->getException("Oh boy", 0, $previousException); $inspector = $this->getInspectorInstance($exception); $this->assertTrue($inspector->hasPreviousException()); $this->assertEquals($previousException, $inspector->getPreviousExceptionInspector()->getException()); }
@covers Whoops\Exception\Inspector::hasPreviousException @covers Whoops\Exception\Inspector::getPreviousExceptionInspector
testPreviousException
php
filp/whoops
tests/Whoops/Exception/InspectorTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Exception/InspectorTest.php
MIT
public function testReturnsWithoutFrames() { $json = $this->getJsonResponseFromHandler($withTrace = false,$jsonApi = false); // Check that the response has the expected keys: $this->assertArrayHasKey('error', $json); $this->assertArrayHasKey('type', $json['error']); $this->assertArrayHasKey('file', $json['error']); $this->assertArrayHasKey('line', $json['error']); // Check the field values: $this->assertEquals($json['error']['file'], __FILE__); $this->assertEquals($json['error']['message'], 'test message'); $this->assertEquals($json['error']['type'], get_class($this->getException())); // Check that the trace is NOT returned: $this->assertArrayNotHasKey('trace', $json['error']); }
@covers Whoops\Handler\JsonResponseHandler::addTraceToOutput @covers Whoops\Handler\JsonResponseHandler::handle
testReturnsWithoutFrames
php
filp/whoops
tests/Whoops/Handler/JsonResponseHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/JsonResponseHandlerTest.php
MIT
public function testReturnsWithFrames() { $json = $this->getJsonResponseFromHandler($withTrace = true,$jsonApi = false); // Check that the trace is returned: $this->assertArrayHasKey('trace', $json['error']); // Check that a random frame has the expected fields $traceFrame = reset($json['error']['trace']); $this->assertArrayHasKey('file', $traceFrame); $this->assertArrayHasKey('line', $traceFrame); $this->assertArrayHasKey('function', $traceFrame); $this->assertArrayHasKey('class', $traceFrame); $this->assertArrayHasKey('args', $traceFrame); }
@covers Whoops\Handler\JsonResponseHandler::addTraceToOutput @covers Whoops\Handler\JsonResponseHandler::handle
testReturnsWithFrames
php
filp/whoops
tests/Whoops/Handler/JsonResponseHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/JsonResponseHandlerTest.php
MIT
public function testReturnsJsonApi() { $json = $this->getJsonResponseFromHandler($withTrace = false,$jsonApi = true); // Check that the response has the expected keys: $this->assertArrayHasKey('errors', $json); $this->assertArrayHasKey('type', $json['errors'][0]); $this->assertArrayHasKey('file', $json['errors'][0]); $this->assertArrayHasKey('line', $json['errors'][0]); // Check the field values: $this->assertEquals($json['errors'][0]['file'], __FILE__); $this->assertEquals($json['errors'][0]['message'], 'test message'); $this->assertEquals($json['errors'][0]['type'], get_class($this->getException())); // Check that the trace is NOT returned: $this->assertArrayNotHasKey('trace', $json['errors']); }
@covers Whoops\Handler\JsonResponseHandler::addTraceToOutput @covers Whoops\Handler\JsonResponseHandler::handle
testReturnsJsonApi
php
filp/whoops
tests/Whoops/Handler/JsonResponseHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/JsonResponseHandlerTest.php
MIT
private function getHandler($logger = null) { return new PlainTextHandler($logger); }
@throws \InvalidArgumentException If argument is not null or a LoggerInterface @param \Psr\Log\LoggerInterface|null $logger @return \Whoops\Handler\PlainTextHandler
getHandler
php
filp/whoops
tests/Whoops/Handler/PlainTextHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PlainTextHandlerTest.php
MIT
public function testConstructor() { $this->expectExceptionOfType('InvalidArgumentException'); $this->getHandler(new StdClass()); }
@covers Whoops\Handler\PlainTextHandler::__construct @covers Whoops\Handler\PlainTextHandler::setLogger
testConstructor
php
filp/whoops
tests/Whoops/Handler/PlainTextHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PlainTextHandlerTest.php
MIT
public function testReturnsWithoutFramesOutput() { $text = $this->getPlainTextFromHandler( $withTrace = false, $withTraceArgs = true, $traceFunctionArgsOutputLimit = 1024, $loggerOnly = false ); // Check that the response has the correct value: // Check that the trace is NOT returned: $this->assertEquals( sprintf( "%s: %s in file %s on line %d\n", get_class($this->getException()), 'test message', __FILE__, self::DEFAULT_EXCEPTION_LINE ), $text ); }
@covers Whoops\Handler\PlainTextHandler::addTraceToOutput @covers Whoops\Handler\PlainTextHandler::handle
testReturnsWithoutFramesOutput
php
filp/whoops
tests/Whoops/Handler/PlainTextHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PlainTextHandlerTest.php
MIT
public function testReturnsWithFramesOutput() { $text = $this->getPlainTextFromHandler( $withTrace = true, $withTraceArgs = false, $traceFunctionArgsOutputLimit = 1024, $loggerOnly = false ); // Check that the response has the correct value: $this->assertStringContains('Stack trace:', $text); // Check that the trace is returned: $this->assertStringContains( sprintf( '%3d. %s->%s() %s:%d', 2, __CLASS__, 'getException', __FILE__, self::DEFAULT_LINE_OF_CALLER ), $text ); }
@covers Whoops\Handler\PlainTextHandler::addTraceToOutput @covers Whoops\Handler\PlainTextHandler::getTraceOutput @covers Whoops\Handler\PlainTextHandler::canOutput @covers Whoops\Handler\PlainTextHandler::handle
testReturnsWithFramesOutput
php
filp/whoops
tests/Whoops/Handler/PlainTextHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PlainTextHandlerTest.php
MIT
public function testReturnsWithFramesAndArgsOutput() { $text = $this->getPlainTextFromHandler( $withTrace = true, $withTraceArgs = true, $traceFunctionArgsOutputLimit = 2048, $loggerOnly = false ); $lines = explode("\n", $text); // Check that the trace is returned with all arguments: $this->assertGreaterThan(60, count($lines)); // Check that the response has the correct value: $this->assertStringContains('Stack trace:', $text); // Check that the trace is returned: $this->assertStringContains( sprintf( '%3d. %s->%s() %s:%d', 2, 'Whoops\Handler\PlainTextHandlerTest', 'getException', __FILE__, self::DEFAULT_LINE_OF_CALLER ), $text ); // Check that the trace arguments are returned: $this->assertStringContains(sprintf( '%s string(%d) "%s"', PlainTextHandler::VAR_DUMP_PREFIX, strlen('test message'), 'test message' ), $text ); }
@covers Whoops\Handler\PlainTextHandler::addTraceToOutput @covers Whoops\Handler\PlainTextHandler::addTraceFunctionArgsToOutput @covers Whoops\Handler\PlainTextHandler::getTraceOutput @covers Whoops\Handler\PlainTextHandler::getFrameArgsOutput @covers Whoops\Handler\PlainTextHandler::canOutput @covers Whoops\Handler\PlainTextHandler::handle
testReturnsWithFramesAndArgsOutput
php
filp/whoops
tests/Whoops/Handler/PlainTextHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PlainTextHandlerTest.php
MIT
public function testReturnsWithFramesAndLimitedArgsOutput() { $text = $this->getPlainTextFromHandler( $withTrace = true, $withTraceArgs = 3, $traceFunctionArgsOutputLimit = 1024, $loggerOnly = false ); // Check that the response has the correct value: $this->assertStringContains('Stack trace:', $text); // Check that the trace is returned: $this->assertStringContains( sprintf( '%3d. %s->%s() %s:%d', 2, 'Whoops\Handler\PlainTextHandlerTest', 'getException', __FILE__, self::DEFAULT_LINE_OF_CALLER ), $text ); // Check that the trace arguments are returned: $this->assertStringContains(sprintf( '%s string(%d) "%s"', PlainTextHandler::VAR_DUMP_PREFIX, strlen('test message'), 'test message' ), $text ); }
@covers Whoops\Handler\PlainTextHandler::addTraceToOutput @covers Whoops\Handler\PlainTextHandler::addTraceFunctionArgsToOutput @covers Whoops\Handler\PlainTextHandler::getTraceOutput @covers Whoops\Handler\PlainTextHandler::getFrameArgsOutput @covers Whoops\Handler\PlainTextHandler::canOutput @covers Whoops\Handler\PlainTextHandler::handle
testReturnsWithFramesAndLimitedArgsOutput
php
filp/whoops
tests/Whoops/Handler/PlainTextHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PlainTextHandlerTest.php
MIT
public function testReturnsWithLoggerOnlyOutput() { $text = $this->getPlainTextFromHandler( $withTrace = true, $withTraceArgs = true, $traceFunctionArgsOutputLimit = 1024, $loggerOnly = true ); // Check that the response has the correct value: $this->assertEquals('', $text); }
@covers Whoops\Handler\PlainTextHandler::loggerOnly @covers Whoops\Handler\PlainTextHandler::handle
testReturnsWithLoggerOnlyOutput
php
filp/whoops
tests/Whoops/Handler/PlainTextHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PlainTextHandlerTest.php
MIT
public function testGetFrameArgsOutputUsesDumper() { $values = []; $dumper = function ($var) use (&$values) { $values[] = $var; }; $handler = $this->getHandler(); $handler->setDumper($dumper); $args = [ ['foo', 'bar', 'buz'], [1, 2, 'Fizz', 4, 'Buzz'], ]; $actual = self::callPrivateMethod($handler, 'dump', [new Frame(['args' => $args[0]])]); $this->assertEquals('', $actual); $this->assertCount(1, $values); $this->assertEquals($args[0], $values[0]->getArgs()); $actual = self::callPrivateMethod($handler, 'dump', [new Frame(['args' => $args[1]])]); $this->assertEquals('', $actual); $this->assertCount(2, $values); $this->assertEquals($args[1], $values[1]->getArgs()); }
@covers Whoops\Handler\PlainTextHandler::loggerOnly @covers Whoops\Handler\PlainTextHandler::handle
testGetFrameArgsOutputUsesDumper
php
filp/whoops
tests/Whoops/Handler/PlainTextHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PlainTextHandlerTest.php
MIT
public function testHandleWithoutErrors() { $run = $this->getRunInstance(); $handler = $this->getHandler(); $run->pushHandler($handler); ob_start(); $run->handleException($this->getException()); ob_get_clean(); // Reached the end without errors $this->assertTrue(true); }
Test that PrettyPageHandle handles the template without any errors. @covers Whoops\Handler\PrettyPageHandler::handle
testHandleWithoutErrors
php
filp/whoops
tests/Whoops/Handler/PrettyPageHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PrettyPageHandlerTest.php
MIT
public function testGetSetPageTitle() { $title = 'My Cool Error Handler'; $handler = $this->getHandler(); $this->assertEquals($handler, $handler->setPageTitle($title)); $this->assertEquals($title, $handler->getPagetitle()); }
@covers Whoops\Handler\PrettyPageHandler::setPageTitle @covers Whoops\Handler\PrettyPageHandler::getPageTitle
testGetSetPageTitle
php
filp/whoops
tests/Whoops/Handler/PrettyPageHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PrettyPageHandlerTest.php
MIT
public function testGetSetResourcePaths() { $path = __DIR__; // guaranteed to be valid! $handler = $this->getHandler(); $this->assertEquals($handler, $handler->addResourcePath($path)); $allPaths = $handler->getResourcePaths(); $this->assertCount(2, $allPaths); $this->assertEquals($allPaths[0], $path); }
@covers Whoops\Handler\PrettyPageHandler::addResourcePath @covers Whoops\Handler\PrettyPageHandler::getResourcePaths
testGetSetResourcePaths
php
filp/whoops
tests/Whoops/Handler/PrettyPageHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PrettyPageHandlerTest.php
MIT
public function testGetSetDataTables() { $handler = $this->getHandler(); // should have no tables by default: $this->assertEmpty($handler->getDataTables()); $tableOne = [ 'ice' => 'cream', 'ice-ice' => 'baby', ]; $tableTwo = [ 'dolan' => 'pls', 'time' => time(), ]; $this->assertEquals($handler, $handler->addDataTable('table 1', $tableOne)); $this->assertEquals($handler, $handler->addDataTable('table 2', $tableTwo)); // should contain both tables: $tables = $handler->getDataTables(); $this->assertCount(2, $tables); $this->assertEquals($tableOne, $tables['table 1']); $this->assertEquals($tableTwo, $tables['table 2']); // should contain only table 1 $this->assertEquals($tableOne, $handler->getDataTables('table 1')); // should return an empty table: $this->assertEmpty($handler->getDataTables('ZIMBABWE!')); }
@covers Whoops\Handler\PrettyPageHandler::getDataTables @covers Whoops\Handler\PrettyPageHandler::addDataTable
testGetSetDataTables
php
filp/whoops
tests/Whoops/Handler/PrettyPageHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PrettyPageHandlerTest.php
MIT
public function testSetCallbackDataTables() { $handler = $this->getHandler(); $this->assertEmpty($handler->getDataTables()); $table1 = function () { return [ 'hammer' => 'time', 'foo' => 'bar', ]; }; $expected1 = ['hammer' => 'time', 'foo' => 'bar']; $table2 = function () use ($expected1) { return [ 'another' => 'table', 'this' => $expected1, ]; }; $expected2 = ['another' => 'table', 'this' => $expected1]; $table3 = function() { return array("oh my" => "how times have changed!"); }; $expected3 = ['oh my' => 'how times have changed!']; // Test inspector parameter in data table callback $table4 = function (\Whoops\Exception\Inspector $inspector) { return array( 'Exception class' => get_class($inspector->getException()), 'Exception message' => $inspector->getExceptionMessage(), ); }; $expected4 = array( 'Exception class' => 'InvalidArgumentException', 'Exception message' => 'Test exception message', ); $inspectorForTable4 = new \Whoops\Exception\Inspector( new \InvalidArgumentException('Test exception message') ); // Sanity check, make sure expected values really are correct. $this->assertSame($expected1, $table1()); $this->assertSame($expected2, $table2()); $this->assertSame($expected3, $table3()); $this->assertSame($expected4, $table4($inspectorForTable4)); $this->assertEquals($handler, $handler->addDataTableCallback('table1', $table1)); $this->assertEquals($handler, $handler->addDataTableCallback('table2', $table2)); $this->assertEquals($handler, $handler->addDataTableCallback('table3', $table3)); $this->assertEquals($handler, $handler->addDataTableCallback('table4', $table4)); $tables = $handler->getDataTables(); $this->assertCount(4, $tables); // Supplied callable is wrapped in a closure $this->assertInstanceOf('Closure', $tables['table1']); $this->assertInstanceOf('Closure', $tables['table2']); $this->assertInstanceOf('Closure', $tables['table3']); $this->assertInstanceOf('Closure', $tables['table4']); // Run each wrapped callable and check results against expected output. $this->assertEquals($expected1, $tables['table1']()); $this->assertEquals($expected2, $tables['table2']()); $this->assertEquals($expected3, $tables['table3']()); $this->assertEquals($expected4, $tables['table4']($inspectorForTable4)); $this->assertSame($tables['table1'], $handler->getDataTables('table1')); $this->assertSame($expected1, call_user_func($handler->getDataTables('table1'))); }
@covers Whoops\Handler\PrettyPageHandler::getDataTables @covers Whoops\Handler\PrettyPageHandler::addDataTableCallback
testSetCallbackDataTables
php
filp/whoops
tests/Whoops/Handler/PrettyPageHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PrettyPageHandlerTest.php
MIT
public function testSetEditorSimple() { $handler = $this->getHandler(); $this->assertEquals($handler, $handler->setEditor('sublime')); $this->assertEquals( $handler->getEditorHref('/foo/bar.php', 10), 'subl://open?url=file://%2Ffoo%2Fbar.php&line=10' ); $this->assertEquals( $handler->getEditorHref('/foo/with space?.php', 2324), 'subl://open?url=file://%2Ffoo%2Fwith%20space%3F.php&line=2324' ); $this->assertEquals( $handler->getEditorHref('/foo/bar/with-dash.php', 0), 'subl://open?url=file://%2Ffoo%2Fbar%2Fwith-dash.php&line=0' ); }
@covers Whoops\Handler\PrettyPageHandler::setEditor @covers Whoops\Handler\PrettyPageHandler::getEditorHref
testSetEditorSimple
php
filp/whoops
tests/Whoops/Handler/PrettyPageHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PrettyPageHandlerTest.php
MIT
public function testSetEditorCallable() { $handler = $this->getHandler(); // Test Callable editor with String return $this->assertEquals($handler, $handler->setEditor(function ($file, $line) { $file = rawurlencode($file); $line = rawurlencode($line); return "http://google.com/search/?q=$file:$line"; })); $this->assertEquals( $handler->getEditorHref('/foo/bar.php', 10), 'http://google.com/search/?q=%2Ffoo%2Fbar.php:10' ); // Then test Callable editor with Array return $this->assertEquals($handler, $handler->setEditor(function ($file, $line) { $file = rawurlencode($file); $line = rawurlencode($line); return [ 'url' => "http://google.com/search/?q=$file:$line", 'ajax' => true, ]; })); $this->assertEquals( $handler->getEditorHref('/foo/bar.php', 10), 'http://google.com/search/?q=%2Ffoo%2Fbar.php:10' ); $this->assertEquals( $handler->getEditorAjax('/foo/bar.php', 10), true ); $this->assertEquals($handler, $handler->setEditor(function ($file, $line) { $file = rawurlencode($file); $line = rawurlencode($line); return [ 'url' => "http://google.com/search/?q=$file:$line", 'ajax' => false, ]; })); $this->assertEquals( $handler->getEditorHref('/foo/bar.php', 10), 'http://google.com/search/?q=%2Ffoo%2Fbar.php:10' ); $this->assertEquals( $handler->getEditorAjax('/foo/bar.php', 10), false ); $this->assertEquals($handler, $handler->setEditor(function ($file, $line) { return false; })); $this->assertEquals( $handler->getEditorHref('/foo/bar.php', 10), false ); }
@covers Whoops\Handler\PrettyPageHandler::setEditor @covers Whoops\Handler\PrettyPageHandler::getEditorHref @covers Whoops\Handler\PrettyPageHandler::getEditorAjax
testSetEditorCallable
php
filp/whoops
tests/Whoops/Handler/PrettyPageHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PrettyPageHandlerTest.php
MIT
public function testAddEditor() { $handler = $this->getHandler(); $this->assertEquals($handler, $handler->addEditor('test-editor', function ($file, $line) { return "cool beans $file:$line"; })); $this->assertEquals($handler, $handler->setEditor('test-editor')); $this->assertEquals( $handler->getEditorHref('hello', 20), 'cool beans hello:20' ); }
@covers Whoops\Handler\PrettyPageHandler::setEditor @covers Whoops\Handler\PrettyPageHandler::addEditor @covers Whoops\Handler\PrettyPageHandler::getEditorHref
testAddEditor
php
filp/whoops
tests/Whoops/Handler/PrettyPageHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/PrettyPageHandlerTest.php
MIT
private function isValidXml($data) { $prev = libxml_use_internal_errors(true); $xml = simplexml_load_string($data); libxml_use_internal_errors($prev); return $xml !== false; }
See if passed string is a valid XML document @param string $data @return bool
isValidXml
php
filp/whoops
tests/Whoops/Handler/XmlResponseHandlerTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Handler/XmlResponseHandlerTest.php
MIT
public function testOutput() { $htmlDumperOutput = new HtmlDumperOutput(); $htmlDumperOutput('first line', 0); $htmlDumperOutput('second line', 2); $expectedOutput = <<<string first line second line string; $this->assertSame($expectedOutput, $htmlDumperOutput->getOutput()); }
@covers Whoops\Util::__invoke @covers Whoops\Util::getOutput
testOutput
php
filp/whoops
tests/Whoops/Util/HtmlDumperOutputTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Util/HtmlDumperOutputTest.php
MIT
public function testTranslateException($expected_output, $exception_code) { $output = Misc::translateErrorCode($exception_code); $this->assertEquals($expected_output, $output); }
@dataProvider provideTranslateException @param string $expected_output @param int $exception_code
testTranslateException
php
filp/whoops
tests/Whoops/Util/MiscTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Util/MiscTest.php
MIT
public function testEscape() { $original = "This is a <a href=''>Foo</a> test string"; $this->assertEquals( $this->helper->escape($original), "This is a &lt;a href=&#039;&#039;&gt;Foo&lt;/a&gt; test string" ); }
@covers Whoops\Util\TemplateHelper::escapeButPreserveUris @covers Whoops\Util\TemplateHelper::escape
testEscape
php
filp/whoops
tests/Whoops/Util/TemplateHelperTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Util/TemplateHelperTest.php
MIT
public function testTemplateVariables() { $this->helper->setVariables([ "name" => "Whoops", "type" => "library", "desc" => "php errors for cool kids", ]); $this->helper->setVariable("name", "Whoops!"); $this->assertEquals($this->helper->getVariable("name"), "Whoops!"); $this->helper->delVariable("type"); $this->assertEquals($this->helper->getVariables(), [ "name" => "Whoops!", "desc" => "php errors for cool kids", ]); }
@covers Whoops\Util\TemplateHelper::setVariables @covers Whoops\Util\TemplateHelper::getVariables @covers Whoops\Util\TemplateHelper::setVariable @covers Whoops\Util\TemplateHelper::getVariable @covers Whoops\Util\TemplateHelper::delVariable
testTemplateVariables
php
filp/whoops
tests/Whoops/Util/TemplateHelperTest.php
https://github.com/filp/whoops/blob/master/tests/Whoops/Util/TemplateHelperTest.php
MIT
public function modifyAssets(Closure $callback): static { $this->assetsModifiers[] = $callback; return $this; }
@param Closure(array $assets): array $callback
modifyAssets
php
moonshine-software/moonshine
src/AssetManager/src/AssetManager.php
https://github.com/moonshine-software/moonshine/blob/master/src/AssetManager/src/AssetManager.php
MIT
public function resources(array $data, bool $newCollection = false): static { if ($newCollection) { $this->resources = []; } $this->resources = array_merge( $this->resources, $data ); return $this; }
Register resources in the system @param list<class-string<ResourceContract>> $data
resources
php
moonshine-software/moonshine
src/Core/src/Core.php
https://github.com/moonshine-software/moonshine/blob/master/src/Core/src/Core.php
MIT
public function getResources(): ResourcesContract { return Resources::make( $this->resolveInstances( $this->resources ) ); }
Get collection of registered resources @return Resources<array-key, ResourceContract>
getResources
php
moonshine-software/moonshine
src/Core/src/Core.php
https://github.com/moonshine-software/moonshine/blob/master/src/Core/src/Core.php
MIT
public function pages(array $data, bool $newCollection = false): static { if ($newCollection) { $this->pages = []; } $this->pages = array_merge( $this->pages, $data ); return $this; }
Register pages in the system @param list<class-string<PageContract>> $data
pages
php
moonshine-software/moonshine
src/Core/src/Core.php
https://github.com/moonshine-software/moonshine/blob/master/src/Core/src/Core.php
MIT
public function getPages(): Pages { return Pages::make( $this->resolveInstances( collect($this->pages)->except('error') ) ); }
Get collection of registered pages @return Pages<PageContract>
getPages
php
moonshine-software/moonshine
src/Core/src/Core.php
https://github.com/moonshine-software/moonshine/blob/master/src/Core/src/Core.php
MIT
protected function extractOnly(iterable $elements, string $type, array &$data): void { foreach ($elements as $element) { if ($element instanceof $type) { $data[] = $element; } if ($element instanceof HasFieldsContract) { $this->extractOnly($element->getFields(), $type, $data); } elseif ($element instanceof HasComponentsContract) { $this->extractOnly($element->getComponents(), $type, $data); } } }
@template TType @param FieldsContract|ComponentsContract|list<ComponentContract> $elements @param class-string<TType> $type @param list<TType> $data @throws Throwable
extractOnly
php
moonshine-software/moonshine
src/Core/src/Collections/Components.php
https://github.com/moonshine-software/moonshine/blob/master/src/Core/src/Collections/Components.php
MIT
protected function getMerged(array ...$items): array { $autoload = []; foreach ($this->groups as $type) { foreach ($items as $value) { $autoload[$type] = array_unique(array_merge($autoload[$type] ?? [], $value[$type] ?? [])); } } return array_filter($autoload); }
@param array<array<string, mixed>> ...$items @return array
getMerged
php
moonshine-software/moonshine
src/Core/src/Collections/OptimizerCollection.php
https://github.com/moonshine-software/moonshine/blob/master/src/Core/src/Collections/OptimizerCollection.php
MIT
protected function isInstanceOf(string $haystack, array|string $needles): bool { foreach (Arr::wrap($needles) as $needle) { if (is_a($haystack, $needle, true)) { return true; } } return false; }
@param class-string $haystack @param list<class-string>|string $needles @return bool
isInstanceOf
php
moonshine-software/moonshine
src/Core/src/Collections/OptimizerCollection.php
https://github.com/moonshine-software/moonshine/blob/master/src/Core/src/Collections/OptimizerCollection.php
MIT
protected function isNotAbstract(string $class): bool { return ! (new ReflectionClass($class))->isAbstract(); }
@param class-string $class @throws ReflectionException @return bool
isNotAbstract
php
moonshine-software/moonshine
src/Core/src/Collections/OptimizerCollection.php
https://github.com/moonshine-software/moonshine/blob/master/src/Core/src/Collections/OptimizerCollection.php
MIT
public function getParentResource(): ?ResourceContract { return $this->parentResource; }
@deprecated Will be removed in 4.0 (unused) @return PT
getParentResource
php
moonshine-software/moonshine
src/Core/src/Traits/HasResource.php
https://github.com/moonshine-software/moonshine/blob/master/src/Core/src/Traits/HasResource.php
MIT
public function setParentResource(?ResourceContract $resource): static { $this->parentResource = $resource; return $this; }
@deprecated Will be removed in 4.0 (unused) @param PT $resource
setParentResource
php
moonshine-software/moonshine
src/Core/src/Traits/HasResource.php
https://github.com/moonshine-software/moonshine/blob/master/src/Core/src/Traits/HasResource.php
MIT
public function setCore(CoreContract $core): void { $this->core = $core; }
We don't keep the Core by default, but there is such an option
setCore
php
moonshine-software/moonshine
src/Core/src/Traits/WithCore.php
https://github.com/moonshine-software/moonshine/blob/master/src/Core/src/Traits/WithCore.php
MIT
public function definition(): array { return [ 'moonshine_user_role_id' => MoonshineUserRole::DEFAULT_ROLE_ID, 'name' => str_replace("'", "", fake()->name()), 'email' => fake()->unique()->safeEmail(), 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 'remember_token' => Str::random(10), ]; }
Define the model's default state. @return array{moonshine_user_role_id: mixed, name: string, email: string, password: string, remember_token: mixed}
definition
php
moonshine-software/moonshine
src/Laravel/database/factories/MoonshineUserFactory.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/database/factories/MoonshineUserFactory.php
MIT
public function definition(): array { return [ 'name' => fake()->name(), ]; }
Define the model's default state. @return array{name: string}
definition
php
moonshine-software/moonshine
src/Laravel/database/factories/MoonshineUserRoleFactory.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/database/factories/MoonshineUserRoleFactory.php
MIT
function toPage( string|PageContract|null $page = null, string|ResourceContract|null $resource = null, array $params = [], bool $redirect = false, null|string|array $fragment = null ): RedirectResponse|string { return moonshineRouter()->getEndpoints()->toPage( page: $page, resource: $resource, params: $params, extra: [ 'redirect' => $redirect, 'fragment' => $fragment, ], ); }
@param class-string<PageContract>|PageContract|null $page @param class-string<ResourceContract>|ResourceContract|null $resource @throws Throwable
toPage
php
moonshine-software/moonshine
src/Laravel/src/helpers.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/helpers.php
MIT
public function toPage( string|PageContract|null $page = null, string|ResourceContract|null $resource = null, array $params = [], array $extra = [], ): string|RedirectResponse { $targetPage = null; $redirect = $extra['redirect'] ?? false; $fragment = $extra['fragment'] ?? null; if (\is_array($fragment)) { $fragment = implode(',', array_map( static fn ($key, $value): string => "$key:$value", array_keys($fragment), $fragment )); } if ($fragment !== null && $fragment !== '') { $params += ['_fragment-load' => $fragment]; } if (\is_null($page) && \is_null($resource)) { throw EndpointException::pageOrResourceRequired(); } if (! \is_null($resource)) { $targetResource = $resource instanceof ResourceContract ? $resource : moonshine()->getResources()->findByClass($resource); $pageUri = $page instanceof PageContract ? $page->getUriKey() : (new UriKey($page))->generate(); /** * Because from the resource we call the method with default CRUD pages, which can be replaced with custom ones * @example toPage(FormPage::class, $resource) -> CustomFormPage */ $targetPage = $targetResource?->getPages()->when( \is_null($page), static fn (Pages $pages) => $pages->first(), static fn (Pages $pages): ?PageContract => $pages->findByUri($pageUri), ); if (! $targetPage instanceof PageContract) { $pageType = PageType::getTypeFromUri($pageUri); $targetPage = $pageType instanceof PageType ? $targetResource?->getPages()->findByType($pageType) : null; } } if (\is_null($resource)) { $targetPage = $page instanceof PageContract ? $page : moonshine()->getPages()->findByClass($page); } if (! $targetPage instanceof PageContract) { throw EndpointException::pageRequired(); } return $redirect ? redirect($targetPage->getRoute($params)) : $targetPage->getRoute($params); }
@param class-string<PageContract>|PageContract|null $page @param class-string<ResourceContract>|ResourceContract|null $resource @throws Throwable
toPage
php
moonshine-software/moonshine
src/Laravel/src/MoonShineEndpoints.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/MoonShineEndpoints.php
MIT
private static function addResourceOrPageTo(string $class, string $to, Closure $between, Closure $replace, string $use = ''): void { if (! file_exists($to)) { return; } $basename = class_basename($class); $namespace = $class; $content = str(file_get_contents($to)); if ($content->contains('->autoload(') || $content->contains('->autoloadMenu(')) { return; } if ($content->contains(['\\' . $basename . ';', '\\' . $basename . ','])) { return; } $tab = static fn (int $times = 1): string => str_repeat(' ', $times * 4); $headSection = $content->before('class '); $replaceContent = $between($content); if ($content->contains($use)) { $use = ''; } $content = str_replace( [ $headSection->value(), $replaceContent->value(), ], [ $headSection->replaceLast(';', (";\nuse $namespace;" . ($use ? "\nuse $use;" : '')))->value(), $replace($replaceContent, $tab)->value(), ], $content->value(), ); file_put_contents($to, $content); }
@param Closure(Stringable $content): Stringable $between @param Closure(Stringable $content, Closure $tab): Stringable $replace
addResourceOrPageTo
php
moonshine-software/moonshine
src/Laravel/src/Commands/MoonShineCommand.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Commands/MoonShineCommand.php
MIT
protected function store(Filesystem $storage, string $cachePath, array $sources): void { $storage->put( $cachePath, '<?php return ' . var_export($sources, true) . ';' . PHP_EOL, ); }
@param Filesystem $storage @param string $cachePath @param array<class-string, array> $sources @return void
store
php
moonshine-software/moonshine
src/Laravel/src/Commands/OptimizeCommand.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Commands/OptimizeCommand.php
MIT
public function updateWith( array $params = [], string|ResourceContract|null $resource = null, string|PageContract|null $page = null, string|array|null $events = null, ?AsyncCallback $callback = null, ): static { /** @var ?CrudResource $resource */ $resource ??= moonshineRequest()->getResource(); $page ??= moonshineRequest()->getPage(); $this->asyncEvents = $events; $this->asyncCallback = $callback; return $this->nowOn( $page, $resource, $params ); }
@param class-string<ResourceContract>|ResourceContract|null $resource @param class-string<PageContract>|PageContract|null $page @throws Throwable
updateWith
php
moonshine-software/moonshine
src/Laravel/src/Components/Fragment.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Components/Fragment.php
MIT
protected function viewData(): array { $nameOfUser = \is_null($this->nameOfUser) ? $this->getDefaultName() : value($this->nameOfUser, $this); $username = \is_null($this->username) ? $this->getDefaultUsername() : value($this->username, $this); $avatar = \is_null($this->avatar) ? $this->getDefaultAvatar() : value($this->avatar, $this); return [ 'route' => $this->route ?? toPage( moonshineConfig()->getPage('profile', ProfilePage::class), ), 'logOutRoute' => $this->logOutRoute ?? rescue(fn (): string => moonshineRouter()->to('logout'), '', report: false), 'avatar' => $avatar, 'nameOfUser' => $nameOfUser, 'username' => $username, 'withBorder' => $this->isWithBorder(), 'menu' => $this->getMenu(), ]; }
@return array<string, mixed> @throws Throwable
viewData
php
moonshine-software/moonshine
src/Laravel/src/Components/Layout/Profile.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Components/Layout/Profile.php
MIT
public function modifyForm(Closure $callback): self { $this->modifyForm = $callback; return $this; }
@param Closure(FormBuilder $form, self $ctx): FormBuilder $callback
modifyForm
php
moonshine-software/moonshine
src/Laravel/src/Components/Layout/Search.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Components/Layout/Search.php
MIT
public function modifyInput(Closure $callback): self { $this->modifyInput = $callback; return $this; }
@param Closure(Text $input, self $ctx): Text $callback
modifyInput
php
moonshine-software/moonshine
src/Laravel/src/Components/Layout/Search.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Components/Layout/Search.php
MIT
public function middleware(array|Closure $middleware): self { return $this->set('middleware', $middleware); }
@deprecated Will be removed in 4.0 (useless) @see for routes use config @param list<class-string>|Closure $middleware
middleware
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function addMiddleware(array|string $middleware): self { if (\is_string($middleware)) { $middleware = [$middleware]; } return $this->set('middleware', [ ...$this->getMiddleware(), ...$middleware, ]); }
@deprecated Will be removed in 4.0 (useless) @see for routes use config @param list<class-string>|class-string $middleware
addMiddleware
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function exceptMiddleware(array|string $except = []): self { $except = \is_string($except) ? [$except] : $except; $middleware = collect($this->getMiddleware()) ->filter(static fn ($class): bool => ! \in_array($class, $except, true)) ->toArray(); return $this->middleware($middleware); }
@deprecated Will be removed in 4.0 (useless) @see for routes use config
exceptMiddleware
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function useProfile(): self { return $this->set('use_profile', true); }
@deprecated Will be removed in 4.0 (useless) @see for routes use config
useProfile
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function useRoutes(): self { return $this->set('use_routes', true); }
@deprecated Will be removed in 4.0 (useless) @see for routes use config
useRoutes
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function disableRoutes(): self { return $this->set('use_routes', false); }
@deprecated Will be removed in 4.0 (useless) @see for routes use config
disableRoutes
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function notFoundException(string|Closure $exception): self { return $this->set('not_found_exception', $exception); }
@param class-string<Throwable>|Closure $exception
notFoundException
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function authEnable(): self { return $this->set('auth.enabled', true); }
@deprecated Will be removed in 4.0 (useless) @see for routes use config
authEnable
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function authDisable(): self { return $this->set('auth.enabled', false); }
@deprecated Will be removed in 4.0 (useless) @see for routes use config
authDisable
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function authPipelines(array|Closure $pipelines): self { return $this->set('auth.pipelines', $pipelines); }
@param list<class-string>|Closure $pipelines
authPipelines
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function authMiddleware(string|Closure $middleware): self { return $this->set('auth.middleware', $middleware); }
@deprecated Will be removed in 4.0 (useless) @see for routes use config @param class-string|Closure $middleware
authMiddleware
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function prefixes(string|Closure $route, string|Closure $page, string|Closure $resource): self { return $this ->set('prefix', $route) ->set('page_prefix', $page) ->set('resource_prefix', $resource) ; }
@deprecated Will be removed in 4.0 (useless) @see for routes use config
prefixes
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function domain(string|Closure $domain): self { return $this->set('domain', $domain); }
@deprecated Will be removed in 4.0 (useless) @see for routes use config
domain
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function layout(string|Closure $layout): self { return $this->set('layout', $layout); }
@param class-string<AbstractLayout>|Closure $layout
layout
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function authorizationRules(Closure $rule): self { $this->authorizationRules->add($rule); return $this; }
@param Closure(ResourceContract $ctx, mixed $user, Ability $ability, mixed $data): bool $rule
authorizationRules
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function changePage(string $old, string $new): self { $pages = $this->getPages(); return $this->set( 'pages', collect($pages) ->map(static fn (string $page): string => $page === $old ? $new : $page) ->toArray() ); }
@param class-string<PageContract> $old @param class-string<PageContract> $new
changePage
php
moonshine-software/moonshine
src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
MIT
public function inLine(string $separator = '', Closure|bool $badge = false, ?Closure $link = null): static { $this->inLine = true; $this->inLineSeparator = $separator; $this->inLineBadge = $badge; $this->inLineLink = $link; return $this; }
@param bool|(Closure(mixed $item, mixed $value, self $ctx): Badge|bool) $badge @param null|(Closure(mixed $item, mixed $value, self $ctx): Link) $link
inLine
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/BelongsToMany.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/BelongsToMany.php
MIT
public function modifyTable(Closure $callback): static { $this->modifyTable = $callback; return $this; }
@param Closure(TableBuilderContract $table, bool $preview): TableBuilderContract $callback
modifyTable
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/BelongsToMany.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/BelongsToMany.php
MIT
protected function viewData(): array { $viewData = [ 'isTreeMode' => $this->isTree(), 'isHorizontalMode' => $this->isHorizontalMode(), 'isSelectMode' => $this->isSelectMode(), 'isAsyncSearch' => $this->isAsyncSearch(), 'asyncSearchUrl' => $this->isAsyncSearch() ? $this->getAsyncSearchUrl() : '', 'isCreatable' => $this->isCreatable(), 'createButton' => $this->getCreateButton(), 'fragmentUrl' => $this->getFragmentUrl(), 'relationName' => $this->getRelationName(), 'keys' => $this->getKeys(), ]; if ($this->isSelectMode()) { $this->customAttributes( $this->getReactiveAttributes(), ); return [ ...$viewData, 'isSearchable' => $this->isSearchable(), 'values' => $this->getAvailableValues(), ]; } if ($this->isTree()) { return [ ...$viewData, 'treeHtml' => $this->toTreeHtml(), ]; } if ($this->isHorizontalMode()) { return [ ...$viewData, 'listHtml' => $this->toListHtml(), ]; } return [ ...$viewData, 'component' => $this->getComponent(), 'componentName' => $this->getComponent()->getName(), 'buttons' => $this->getButtons(), ]; }
@return array<string, mixed> @throws Throwable
viewData
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/BelongsToMany.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/BelongsToMany.php
MIT
public function redirectAfter(Closure $callback): static { $this->redirectAfter = $callback; return $this; }
@param Closure(int $parentId, static $field): string $callback
redirectAfter
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasMany.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasMany.php
MIT
public function modifyCreateButton(Closure $callback): static { $this->modifyCreateButton = $callback; return $this; }
@param Closure(ActionButtonContract $button, static $ctx): ActionButtonContract $callback
modifyCreateButton
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasMany.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasMany.php
MIT
public function modifyEditButton(Closure $callback): static { $this->modifyEditButton = $callback; return $this; }
@param Closure(ActionButtonContract $button, static $ctx): ActionButtonContract $callback
modifyEditButton
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasMany.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasMany.php
MIT
public function modifyItemButtons(Closure $callback): static { $this->modifyItemButtons = $callback; return $this; }
@param Closure(ActionButtonContract $detail, ActionButtonContract $edit, ActionButtonContract $delete, ActionButtonContract $massDelete, static $ctx): array $callback
modifyItemButtons
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasMany.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasMany.php
MIT
public function modifyTable(Closure $callback): static { $this->modifyTable = $callback; return $this; }
@param Closure(TableBuilderContract $table, bool $preview): TableBuilderContract $callback
modifyTable
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasMany.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasMany.php
MIT
public function modifyBuilder(Closure $builder): static { $this->modifyBuilder = $builder; return $this; }
@param Closure(Relation $relation, self $field): Relation $builder
modifyBuilder
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasMany.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasMany.php
MIT
protected function viewData(): array { return $this->isModalMode() ? $this->modalViewData() : $this->defaultViewData() ; }
@return array<string, mixed> @throws Throwable
viewData
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasMany.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasMany.php
MIT
protected function modalViewData(): array { $components = new Components(); $flexComponents = new Components(); if ($this->isCreatable()) { $flexComponents->add($this->getCreateButton()); } if (! \is_null($this->buttons)) { $flexComponents->add($this->getButtons()); } if ($flexComponents->isNotEmpty()) { $components->add(Flex::make($flexComponents)->justifyAlign('between')); } $components->add(LineBreak::make()); $components->add($this->getComponent()); return [ 'component' => $this->getModalButton( $components, $this->getLabel(), $this->getRelationName() ), ]; }
@return array<string, mixed> @throws Throwable
modalViewData
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasMany.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasMany.php
MIT
public function defaultViewData(): array { return [ 'component' => $this->getComponent(), 'isCreatable' => $this->isCreatable(), 'createButton' => $this->getCreateButton(), 'buttons' => $this->getButtons(), ]; }
@return array<string, mixed> @throws Throwable
defaultViewData
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasMany.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasMany.php
MIT
public function redirectAfter(Closure $callback): static { $this->redirectAfter = $callback; return $this; }
@param Closure(int $parentId, static $field): string $callback
redirectAfter
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasOne.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasOne.php
MIT
public function modifyForm(Closure $callback): static { $this->modifyForm = $callback; return $this; }
@param Closure(FormBuilderContract $table): FormBuilderContract $callback
modifyForm
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasOne.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasOne.php
MIT
public function modifyTable(Closure $callback): static { $this->modifyTable = $callback; return $this; }
@param Closure(TableBuilderContract $table): TableBuilderContract $callback
modifyTable
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasOne.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasOne.php
MIT
protected function viewData(): array { // On the form when outsideComponent is false, // the HasOne field can be displayed only in modalMode. if (! $this->outsideComponent) { $this->modalMode(); } if (\is_null($this->getRelatedModel()?->getKey())) { return ['component' => '']; } return [ 'component' => $this->isModalMode() ? $this->getModalButton( Components::make([$this->getComponent()]), $this->getLabel(), $this->getRelationName() ) : $this->getComponent(), ]; }
@throws FieldException @return array<string, mixed> @throws Throwable
viewData
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/HasOne.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/HasOne.php
MIT
protected function findResource(?string $classString = null): ModelResource { if ($this->hasResource()) { return $this->getResource(); } /** @var ?ModelResource $resource */ $resource = $classString ? moonshine()->getResources()->findByClass($classString) : moonshine()->getResources()->findByUri( str($this->getRelationName()) ->singular() ->append('Resource') ->kebab() ->value(), ); if (\is_null($resource) && $this->isMorph()) { /** @var ModelResource $resource */ $resource = moonshine()->getResources()->findByUri( moonshineRequest()->getResourceUri(), ); } return tap( $resource, function (?ModelResource $resource): void { throw_if( \is_null($resource), FieldException::resourceRequired(static::class, $this->getRelationName()), ); }, ); }
@param ?class-string<ModelResource> $classString @throws Throwable
findResource
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/ModelRelationField.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/ModelRelationField.php
MIT
public function types(array $types): static { $this->asyncSearch(); $this->searchColumns = collect($types) ->mapWithKeys( static fn ( string|array $searchColumn, string $type ): array => [$type => \is_array($searchColumn) ? $searchColumn[0] : $searchColumn] ) ->toArray(); $this->types = collect($types) ->mapWithKeys( static fn ( string|array $searchColumn, string $type ): array => [$type => \is_array($searchColumn) ? $searchColumn[1] : class_basename($type)] ) ->toArray(); return $this; }
@param array<class-string<Model>, string|array> $types
types
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/MorphTo.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/MorphTo.php
MIT
public function modifyTable(Closure $callback): static { $this->modifyTable = $callback; return $this; }
@param Closure(TableBuilder $table, bool $preview): TableBuilder $callback
modifyTable
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/RelationRepeater.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/RelationRepeater.php
MIT
public function modifyRemoveButton(Closure $callback): self { $this->modifyRemoveButton = $callback; return $this; }
@param Closure(ActionButton $button, self $field): ActionButton $callback
modifyRemoveButton
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/RelationRepeater.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/RelationRepeater.php
MIT
public function modifyCreateButton(Closure $callback): self { $this->modifyCreateButton = $callback; return $this; }
@param Closure(ActionButton $button, self $field): ActionButton $callback
modifyCreateButton
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/RelationRepeater.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/RelationRepeater.php
MIT
protected function resolvePreview(): string|Renderable { return $this ->getComponent() ->simple() ->preview() ->render(); }
@throws ContainerExceptionInterface @throws Throwable @throws NotFoundExceptionInterface
resolvePreview
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/RelationRepeater.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/RelationRepeater.php
MIT
protected function viewData(): array { return [ 'component' => $this->getComponent(), ]; }
@return array<string, mixed> @throws Throwable
viewData
php
moonshine-software/moonshine
src/Laravel/src/Fields/Relationships/RelationRepeater.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Fields/Relationships/RelationRepeater.php
MIT
public function modifyButton(Closure $callback): static { $this->modifyButton = $callback; return $this; }
@param Closure(ActionButtonContract $button, static $ctx): ActionButtonContract $callback
modifyButton
php
moonshine-software/moonshine
src/Laravel/src/Handlers/Handler.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Handlers/Handler.php
MIT
public function notifyUsers(array|Closure $ids): static { $this->notifyUsers = $ids; return $this; }
@param array|Closure(static $ctx): array $ids
notifyUsers
php
moonshine-software/moonshine
src/Laravel/src/Handlers/Handler.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Handlers/Handler.php
MIT
public function authorize(): bool { return MoonShineAuth::getGuard()->guest(); }
Determine if the user is authorized to make this request.
authorize
php
moonshine-software/moonshine
src/Laravel/src/Http/Requests/LoginFormRequest.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Http/Requests/LoginFormRequest.php
MIT
public function rules(): array { return [ 'username' => ['required'], 'password' => ['required'], ]; }
Get the validation rules that apply to the request. @return array{username: string[], password: string[]}
rules
php
moonshine-software/moonshine
src/Laravel/src/Http/Requests/LoginFormRequest.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Http/Requests/LoginFormRequest.php
MIT
public function authenticate(): void { $this->ensureIsNotRateLimited(); if (! MoonShineAuth::getGuard()->attempt( $this->getCredentials(), $this->boolean('remember') )) { RateLimiter::hit($this->getThrottleKey()); $this->validationException(); } session()->regenerate(); RateLimiter::clear($this->getThrottleKey()); }
Attempt to authenticate the request's credentials. @throws ValidationException
authenticate
php
moonshine-software/moonshine
src/Laravel/src/Http/Requests/LoginFormRequest.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Http/Requests/LoginFormRequest.php
MIT
public function authorize(): bool { return MoonShineAuth::getGuard()->check(); }
Determine if the user is authorized to make this request.
authorize
php
moonshine-software/moonshine
src/Laravel/src/Http/Requests/ProfileFormRequest.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Http/Requests/ProfileFormRequest.php
MIT
public function rules(): array { $fieldRules = data_get( $this->getResource()?->getRules(), request()->getScalar('field'), ); $valueRules = ['present']; if (\is_string($fieldRules)) { $valueRules[] = $valueRules; } if (\is_array($fieldRules)) { $valueRules = array_merge($valueRules, $fieldRules); } return [ 'field' => ['required'], 'value' => $valueRules, ]; }
@return array{field: string[], value: string[]}
rules
php
moonshine-software/moonshine
src/Laravel/src/Http/Requests/Resources/UpdateColumnFormRequest.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Http/Requests/Resources/UpdateColumnFormRequest.php
MIT
public function toArray($notifiable): array { return [ 'message' => $this->message, 'button' => \is_null($this->button) ? [] : $this->button->toArray(), 'color' => $this->color, 'icon' => $this->icon, ]; }
@return array{message: string, button: array, color: ?string}
toArray
php
moonshine-software/moonshine
src/Laravel/src/Notifications/DatabaseNotification.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Notifications/DatabaseNotification.php
MIT
protected function getDetailComponents(?DataWrapperContract $item): array { return [ Fragment::make([ $this->getResource()->modifyDetailComponent( $this->getDetailComponent($item, $this->getResource()->getDetailFields()) ), ])->name('crud-detail'), ]; }
@return list<ComponentContract> @throws MoonShineComponentException @throws PageException @throws Throwable
getDetailComponents
php
moonshine-software/moonshine
src/Laravel/src/Pages/Crud/DetailPage.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Pages/Crud/DetailPage.php
MIT
public function modifyButton(Closure $callback): self { $this->modifyButton = $callback; return $this; }
@param Closure(ActionButtonContract $btn, self $ctx): ActionButtonContract $callback
modifyButton
php
moonshine-software/moonshine
src/Laravel/src/QueryTags/QueryTag.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/QueryTags/QueryTag.php
MIT
protected function fragmentMetrics(): ?Closure { return null; }
@return null|Closure(array $components): Fragment
fragmentMetrics
php
moonshine-software/moonshine
src/Laravel/src/Resources/CrudResource.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Resources/CrudResource.php
MIT
public function getItemsResolver(): ?Closure { return null; }
@return null|Closure(iterable $items, TableBuilderContract $table): iterable
getItemsResolver
php
moonshine-software/moonshine
src/Laravel/src/Resources/CrudResource.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Resources/CrudResource.php
MIT