Файловый менеджер - Редактировать - /home/easybachat/hisabat365.com/4a7891/livewire.tar
Ðазад
livewire/src/Attribute.php 0000644 00000000233 15060132176 0011634 0 ustar 00 <?php namespace Livewire; use Livewire\Features\SupportAttributes\Attribute as BaseAttribute; abstract class Attribute extends BaseAttribute { // } livewire/src/Wrapped.php 0000644 00000001431 15060132176 0011274 0 ustar 00 <?php namespace Livewire; class Wrapped { protected $fallback; function __construct(public $target) {} function withFallback($fallback) { $this->fallback = $fallback; return $this; } function __call($method, $params) { if (! method_exists($this->target, $method)) return value($this->fallback); try { return ImplicitlyBoundMethod::call(app(), [$this->target, $method], $params); } catch (\Throwable $e) { $shouldPropagate = true; $stopPropagation = function () use (&$shouldPropagate) { $shouldPropagate = false; }; trigger('exception', $this->target, $e, $stopPropagation); $shouldPropagate && throw $e; } } } livewire/src/Features/SupportBladeAttributes/SupportBladeAttributes.php 0000644 00000001104 15060132176 0022573 0 ustar 00 <?php namespace Livewire\Features\SupportBladeAttributes; use Livewire\WireDirective; use Illuminate\View\ComponentAttributeBag; use Livewire\ComponentHook; class SupportBladeAttributes extends ComponentHook { static function provide() { ComponentAttributeBag::macro('wire', function ($name) { $entries = head((array) $this->whereStartsWith('wire:'.$name)); $directive = head(array_keys($entries)); $value = head(array_values($entries)); return new WireDirective($name, $directive, $value); }); } } livewire/src/Features/SupportLockedProperties/CannotUpdateLockedPropertyException.php 0000644 00000000447 15060132176 0025464 0 ustar 00 <?php namespace Livewire\Features\SupportLockedProperties; class CannotUpdateLockedPropertyException extends \Exception { public function __construct(public $property) { parent::__construct( 'Cannot update locked property: ['.$this->property.']' ); } } livewire/src/Features/SupportLockedProperties/BaseLocked.php 0000644 00000000465 15060132176 0020325 0 ustar 00 <?php namespace Livewire\Features\SupportLockedProperties; use Livewire\Features\SupportAttributes\Attribute as LivewireAttribute; #[\Attribute] class BaseLocked extends LivewireAttribute { public function update() { throw new CannotUpdateLockedPropertyException($this->getName()); } } livewire/src/Features/SupportNestedComponentListeners/SupportNestedComponentListeners.php 0000644 00000004063 15060132176 0026442 0 ustar 00 <?php namespace Livewire\Features\SupportNestedComponentListeners; use function Livewire\store; use Livewire\Drawer\Utils; use Livewire\ComponentHook; class SupportNestedComponentListeners extends ComponentHook { public function mount($params, $parent) { // If a Livewire component is passed an attribute with an "@" // (<livewire:child @some-event="handler") // Then turn it into an Alpine listener and add it to a // "attributes" key in the store so it can be added to the // component's memo and passed again to the server on subsequent // requests to ensure it is always added as an HTML attribute // to the root element of the component... foreach ($params as $key => $value) { if (str($key)->startsWith('@')) { // any kebab-cased parameters passed in will have been converted to camelCase // so we need to convert back to kebab to ensure events are valid in html $fullEvent = str($key)->after('@')->kebab(); $attributeKey = 'x-on:'.$fullEvent; $attributeValue = "\$wire.\$parent.".$value; store($this->component)->push('attributes', $attributeValue, $attributeKey); } } } public function render($view, $data) { return function ($html, $replaceHtml) { $attributes = store($this->component)->get('attributes', false); if (! $attributes) return; $replaceHtml(Utils::insertAttributesIntoHtmlRoot($html, $attributes)); }; } public function dehydrate($context) { $attributes = store($this->component)->get('attributes', false); if (! $attributes) return; $attributes && $context->addMemo('attributes', $attributes); } public function hydrate($memo) { if (! isset($memo['attributes'])) return; $attributes = $memo['attributes']; // Store the attributes for later dehydration... store($this->component)->set('attributes', $attributes); } } livewire/src/Features/SupportNestingComponents/SupportNestingComponents.php 0000644 00000010606 15060132176 0023600 0 ustar 00 <?php namespace Livewire\Features\SupportNestingComponents; use function Livewire\trigger; use function Livewire\store; use function Livewire\on; use Livewire\ComponentHook; use Livewire\Drawer\Utils; class SupportNestingComponents extends ComponentHook { static function provide() { on('pre-mount', function ($name, $params, $key, $parent, $hijack) { // If this has already been rendered spoof it... if ($parent && static::hasPreviouslyRenderedChild($parent, $key)) { [$tag, $childId] = static::getPreviouslyRenderedChild($parent, $key); $finish = trigger('mount.stub', $tag, $childId, $params, $parent, $key); $html = "<{$tag} wire:id=\"{$childId}\"></{$tag}>"; static::setParentChild($parent, $key, $tag, $childId); $hijack($finish($html)); } }); on('mount', function ($component, $params, $key, $parent) { $start = null; if ($parent && config('app.debug')) $start = microtime(true); static::setParametersToMatchingProperties($component, $params); return function ($html) use ($component, $key, $parent, $start) { if ($parent) { if (config('app.debug')) trigger('profile', 'child:'.$component->getId(), $parent->getId(), [$start, microtime(true)]); preg_match('/<([a-zA-Z0-9\-]*)/', $html, $matches, PREG_OFFSET_CAPTURE); $tag = $matches[1][0]; static::setParentChild($parent, $key, $tag, $component->getId()); } }; }); } function hydrate($memo) { $children = $memo['children']; static::setPreviouslyRenderedChildren($this->component, $children); $this->ifThisComponentIsAChildThatHasBeenRemovedByTheParent(function () { // Let's skip its render so that we aren't wasting extra rendering time // on a component that has already been thrown-away by its parent... $this->component->skipRender(); }); } function dehydrate($context) { $skipRender = $this->storeGet('skipRender'); if ($skipRender) $this->keepRenderedChildren(); $this->storeRemovedChildrenToReferenceWhenThoseChildrenHydrateSoWeCanSkipTheirRenderAndAvoideUselessWork(); $context->addMemo('children', $this->getChildren()); } function getChildren() { return $this->storeGet('children', []); } function setChild($key, $tag, $id) { $this->storePush('children', [$tag, $id], $key); } static function setParentChild($parent, $key, $tag, $id) { store($parent)->push('children', [$tag, $id], $key); } static function setPreviouslyRenderedChildren($component, $children) { store($component)->set('previousChildren', $children); } static function hasPreviouslyRenderedChild($parent, $key) { return array_key_exists($key, store($parent)->get('previousChildren', [])); } static function getPreviouslyRenderedChild($parent, $key) { return store($parent)->get('previousChildren')[$key]; } function keepRenderedChildren() { $this->storeSet('children', $this->storeGet('previousChildren')); } static function setParametersToMatchingProperties($component, $params) { // Assign all public component properties that have matching parameters. collect(array_intersect_key($params, Utils::getPublicPropertiesDefinedOnSubclass($component))) ->each(function ($value, $property) use ($component) { $component->{$property} = $value; }); } protected function storeRemovedChildrenToReferenceWhenThoseChildrenHydrateSoWeCanSkipTheirRenderAndAvoideUselessWork() { // Get a list of children that we're "removed" in this request... $removedChildren = array_diff_key($this->storeGet('previousChildren', []), $this->getChildren()); foreach ($removedChildren as $key => $child) { store()->push('removedChildren', $key, $child[1]); } } protected function ifThisComponentIsAChildThatHasBeenRemovedByTheParent($callback) { $removedChildren = store()->get('removedChildren', []); if (isset($removedChildren[$this->component->getId()])) { $callback(); store()->unset('removedChildren', $this->component->getId()); } } } livewire/src/Features/SupportDisablingBackButtonCache/HandlesDisablingBackButtonCache.php 0000644 00000000546 15060132176 0025744 0 ustar 00 <?php namespace Livewire\Features\SupportDisablingBackButtonCache; trait HandlesDisablingBackButtonCache { function disableBackButtonCache() { SupportDisablingBackButtonCache::$disableBackButtonCache = true; } function enableBackButtonCache() { SupportDisablingBackButtonCache::$disableBackButtonCache = false; } } livewire/src/Features/SupportDisablingBackButtonCache/DisableBackButtonCacheMiddleware.php 0000644 00000001472 15060132176 0026111 0 ustar 00 <?php namespace Livewire\Features\SupportDisablingBackButtonCache; use Closure; use Symfony\Component\HttpFoundation\Response; class DisableBackButtonCacheMiddleware { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $response = $next($request); if ($response instanceof Response && SupportDisablingBackButtonCache::$disableBackButtonCache){ $response->headers->add([ "Pragma" => "no-cache", "Expires" => "Fri, 01 Jan 1990 00:00:00 GMT", "Cache-Control" => "no-cache, must-revalidate, no-store, max-age=0, private", ]); } return $response; } } livewire/src/Features/SupportDisablingBackButtonCache/SupportDisablingBackButtonCache.php 0000644 00000001141 15060132176 0026032 0 ustar 00 <?php namespace Livewire\Features\SupportDisablingBackButtonCache; use Livewire\ComponentHook; class SupportDisablingBackButtonCache extends ComponentHook { public static $disableBackButtonCache = false; public static function provide() { $kernel = app()->make(\Illuminate\Contracts\Http\Kernel::class); if ($kernel->hasMiddleware(DisableBackButtonCacheMiddleware::class)) { return; } $kernel->pushMiddleware(DisableBackButtonCacheMiddleware::class); } public function boot() { static::$disableBackButtonCache = true; } } livewire/src/Features/SupportWireables/SupportWireables.php 0000644 00000000362 15060132176 0020276 0 ustar 00 <?php namespace Livewire\Features\SupportWireables; use Livewire\ComponentHook; class SupportWireables extends ComponentHook { static function provide() { app('livewire')->propertySynthesizer(WireableSynth::class); } } livewire/src/Features/SupportWireables/WireableSynth.php 0000644 00000001653 15060132176 0017550 0 ustar 00 <?php namespace Livewire\Features\SupportWireables; use Livewire\Wireable; use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth; class WireableSynth extends Synth { public static $key = 'wrbl'; static function match($target) { return is_object($target) && $target instanceof Wireable; } function dehydrate($target, $dehydrateChild) { $data = $target->toLivewire(); foreach ($data as $key => $child) { $data[$key] = $dehydrateChild($key, $child); } return [ $data, ['class' => get_class($target)], ]; } function hydrate($value, $meta, $hydrateChild) { foreach ($value as $key => $child) { $value[$key] = $hydrateChild($key, $child); } return $meta['class']::fromLivewire($value); } function set(&$target, $key, $value) { $target->{$key} = $value; } } livewire/src/Features/SupportChecksumErrorDebugging/SupportChecksumErrorDebugging.php 0000644 00000005222 15060132176 0025424 0 ustar 00 <?php namespace Livewire\Features\SupportChecksumErrorDebugging; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\File; class SupportChecksumErrorDebugging { function boot() { // @todo: dont write to this file unless the command is running... return; $file = storage_path('framework/cache/lw-checksum-log.json'); Artisan::command('livewire:monitor-checksum', function () use ($file) { File::put($file, json_encode(['checksums' => [], 'failure' => null])); $this->info('Monitoring for checksum errors...'); while (true) { $cache = json_decode(File::get($file), true); if ($cache['failure']) { $this->info('Failure: '.$cache['failure']); $cache['failure'] = null; } File::put($file, json_encode($cache)); sleep(1); } })->purpose('Debug checksum errors in Livewire'); on('checksum.fail', function ($checksum, $comparitor, $tamperedSnapshot) use ($file) { $cache = json_decode(File::get($file), true); if (! isset($cache['checksums'][$checksum])) return; $canonicalSnapshot = $cache['checksums'][$checksum]; $good = $this->array_diff_assoc_recursive($canonicalSnapshot, $tamperedSnapshot); $bad = $this->array_diff_assoc_recursive($tamperedSnapshot, $canonicalSnapshot); $cache['failure'] = "\nBefore: ".json_encode($good)."\nAfter: ".json_encode($bad); File::put($file, json_encode($cache)); }); on('checksum.generate', function ($checksum, $snapshot) use ($file) { $cache = json_decode(File::get($file), true); $cache['checksums'][$checksum] = $snapshot; File::put($file, json_encode($cache)); }); } // https://www.php.net/manual/en/function.array-diff-assoc.php#111675 function array_diff_assoc_recursive($array1, $array2) { $difference=array(); foreach($array1 as $key => $value) { if( is_array($value) ) { if( !isset($array2[$key]) || !is_array($array2[$key]) ) { $difference[$key] = $value; } else { $new_diff = $this->array_diff_assoc_recursive($value, $array2[$key]); if( !empty($new_diff) ) $difference[$key] = $new_diff; } } else if( !array_key_exists($key,$array2) || $array2[$key] !== $value ) { $difference[$key] = $value; } } return $difference; } } livewire/src/Features/SupportStreaming/SupportStreaming.php 0000644 00000001771 15060132176 0020333 0 ustar 00 <?php namespace Livewire\Features\SupportStreaming; use Livewire\ComponentHook; class SupportStreaming extends ComponentHook { protected static $response; public function stream($name, $content, $replace = false) { static::ensureStreamResponseStarted(); static::streamContent(['name' => $name, 'content' => $content, 'replace' => $replace]); } public static function ensureStreamResponseStarted() { if (static::$response) return; static::$response = response()->stream(null , 200, [ 'Cache-Control' => 'no-cache', 'Content-Type' => 'text/event-stream', 'X-Accel-Buffering' => 'no', 'X-Livewire-Stream' => true, ]); static::$response->sendHeaders(); } public static function streamContent($body) { echo json_encode(['stream' => true, 'body' => $body, 'endStream' => true]); if (ob_get_level() > 0) { ob_flush(); } flush(); } } livewire/src/Features/SupportStreaming/HandlesStreaming.php 0000644 00000000464 15060132176 0020233 0 ustar 00 <?php namespace Livewire\Features\SupportStreaming; use Livewire\ComponentHookRegistry; trait HandlesStreaming { function stream($to, $content, $replace = false) { $hook = ComponentHookRegistry::getHook($this, SupportStreaming::class); $hook->stream($to, $content, $replace); } } livewire/src/Features/SupportRedirects/HandlesRedirects.php 0000644 00000001726 15060132176 0020223 0 ustar 00 <?php namespace Livewire\Features\SupportRedirects; use function Livewire\store; trait HandlesRedirects { public function redirect($url, $navigate = false) { store($this)->set('redirect', $url); if ($navigate) store($this)->set('redirectUsingNavigate', true); $shouldSkipRender = ! config('livewire.render_on_redirect', false); $shouldSkipRender && $this->skipRender(); } public function redirectRoute($name, $parameters = [], $absolute = true, $navigate = false) { $this->redirect(route($name, $parameters, $absolute), $navigate); } public function redirectIntended($default = '/', $navigate = false) { $url = session()->pull('url.intended', $default); $this->redirect($url, $navigate); } public function redirectAction($name, $parameters = [], $absolute = true, $navigate = false) { $this->redirect(action($name, $parameters, $absolute), $navigate); } } livewire/src/Features/SupportRedirects/SupportRedirects.php 0000644 00000004264 15060132176 0020321 0 ustar 00 <?php namespace Livewire\Features\SupportRedirects; use Livewire\Attributes\Modelable; use Livewire\Mechanisms\HandleRequests\HandleRequests; use Livewire\ComponentHook; use Livewire\Component; use function Livewire\on; class SupportRedirects extends ComponentHook { public static $redirectorCacheStack = []; public static $atLeastOneMountedComponentHasRedirected = false; public static function provide() { // Wait until all components have been processed... on('response', function ($response) { // If there was no redirect on a subsequent component update, clear flash session data. if (! static::$atLeastOneMountedComponentHasRedirected && app()->has('session.store')) { session()->forget(session()->get('_flash.new')); } }); on('flush-state', function () { static::$atLeastOneMountedComponentHasRedirected = false; }); } public function boot() { // Put Laravel's redirector aside and replace it with our own custom one. static::$redirectorCacheStack[] = app('redirect'); app()->bind('redirect', function () { $redirector = app(Redirector::class)->component($this->component); if (app()->has('session.store')) { $redirector->setSession(app('session.store')); } return $redirector; }); } public function dehydrate($context) { // Put the old redirector back into the container. app()->instance('redirect', array_pop(static::$redirectorCacheStack)); $to = $this->storeGet('redirect'); $usingNavigate = $this->storeGet('redirectUsingNavigate'); if (is_subclass_of($to, Component::class)) { $to = url()->action($to); } if ($to && ! app(HandleRequests::class)->isLivewireRequest()) { abort(redirect($to)); } if (! $to) return; $context->addEffect('redirect', $to); $usingNavigate && $context->addEffect('redirectUsingNavigate', true); if (! $context->isMounting()) { static::$atLeastOneMountedComponentHasRedirected = true; } } } livewire/src/Features/SupportRedirects/Redirector.php 0000644 00000001717 15060132176 0017102 0 ustar 00 <?php namespace Livewire\Features\SupportRedirects; use Livewire\Component; use Illuminate\Routing\Redirector as BaseRedirector; class Redirector extends BaseRedirector { protected $component; public function to($path, $status = 302, $headers = [], $secure = null) { $this->component->redirect($this->generator->to($path, [], $secure)); return $this; } public function away($path, $status = 302, $headers = []) { return $this->to($path, $status, $headers); } public function with($key, $value = null) { $key = is_array($key) ? $key : [$key => $value]; foreach ($key as $k => $v) { $this->session->flash($k, $v); } return $this; } public function component(Component $component) { $this->component = $component; return $this; } public function response($to) { return $this->createRedirect($to, 302, []); } } livewire/src/Features/SupportRedirects/TestsRedirects.php 0000644 00000002056 15060132176 0017744 0 ustar 00 <?php namespace Livewire\Features\SupportRedirects; use Livewire\Component; use PHPUnit\Framework\Assert as PHPUnit; trait TestsRedirects { public function assertRedirect($uri = null) { if (is_subclass_of($uri, Component::class)) { $uri = url()->action($uri); } if (! app('livewire')->isLivewireRequest()) { $this->lastState->getResponse()->assertRedirect($uri); return $this; } PHPUnit::assertArrayHasKey( 'redirect', $this->effects, 'Component did not perform a redirect.' ); if (! is_null($uri)) { PHPUnit::assertSame(url($uri), url($this->effects['redirect'])); } return $this; } public function assertRedirectToRoute($name, $parameters = []) { $uri = route($name, $parameters); return $this->assertRedirect($uri); } public function assertNoRedirect() { PHPUnit::assertTrue(! isset($this->effects['redirect'])); return $this; } } livewire/src/Features/SupportComputed/BaseComputed.php 0000644 00000007107 15060132176 0017206 0 ustar 00 <?php namespace Livewire\Features\SupportComputed; use function Livewire\invade; use function Livewire\on; use function Livewire\off; use Livewire\Features\SupportAttributes\Attribute; use Illuminate\Support\Facades\Cache; #[\Attribute] class BaseComputed extends Attribute { protected $requestCachedValue; function __construct( public $persist = false, public $seconds = 3600, // 1 hour... public $cache = false, public $key = null, public $tags = null, ) {} function boot() { off('__get', $this->handleMagicGet(...)); on('__get', $this->handleMagicGet(...)); off('__unset', $this->handleMagicUnset(...)); on('__unset', $this->handleMagicUnset(...)); } function call() { throw new CannotCallComputedDirectlyException( $this->component->getName(), $this->getName(), ); } protected function handleMagicGet($target, $property, $returnValue) { if ($target !== $this->component) return; if ($this->generatePropertyName($property) !== $this->getName()) return; if ($this->persist) { $returnValue($this->handlePersistedGet()); return; } if ($this->cache) { $returnValue($this->handleCachedGet()); return; } $returnValue( $this->requestCachedValue ??= $this->evaluateComputed() ); } protected function handleMagicUnset($target, $property) { if ($target !== $this->component) return; if ($property !== $this->getName()) return; if ($this->persist) { $this->handlePersistedUnset(); return; } if ($this->cache) { $this->handleCachedUnset(); return; } unset($this->requestCachedValue); } protected function handlePersistedGet() { $key = $this->generatePersistedKey(); $closure = fn () => $this->evaluateComputed(); return match(Cache::supportsTags() && !empty($this->tags)) { true => Cache::tags($this->tags)->remember($key, $this->seconds, $closure), default => Cache::remember($key, $this->seconds, $closure) }; } protected function handleCachedGet() { $key = $this->generateCachedKey(); $closure = fn () => $this->evaluateComputed(); return match(Cache::supportsTags() && !empty($this->tags)) { true => Cache::tags($this->tags)->remember($key, $this->seconds, $closure), default => Cache::remember($key, $this->seconds, $closure) }; } protected function handlePersistedUnset() { $key = $this->generatePersistedKey(); Cache::forget($key); } protected function handleCachedUnset() { $key = $this->generateCachedKey(); Cache::forget($key); } protected function generatePersistedKey() { if ($this->key) return $this->key; return 'lw_computed.'.$this->component->getId().'.'.$this->getName(); } protected function generateCachedKey() { if ($this->key) return $this->key; return 'lw_computed.'.$this->component->getName().'.'.$this->getName(); } protected function evaluateComputed() { return invade($this->component)->{parent::getName()}(); } public function getName() { return $this->generatePropertyName(parent::getName()); } private function generatePropertyName($value) { return str($value)->camel()->toString(); } } livewire/src/Features/SupportComputed/SupportLegacyComputedPropertySyntax.php 0000644 00000004455 15060132176 0024114 0 ustar 00 <?php namespace Livewire\Features\SupportComputed; use Livewire\ComponentHook; use Livewire\Drawer\Utils as SyntheticUtils; use function Livewire\on; use function Livewire\store; use function Livewire\wrap; class SupportLegacyComputedPropertySyntax extends ComponentHook { static function provide() { on('__get', function ($target, $property, $returnValue) { if (static::hasComputedProperty($target, $property)) { $returnValue(static::getComputedProperty($target, $property)); } }); on('__unset', function ($target, $property) { if (static::hasComputedProperty($target, $property)) { store($target)->unset('computedProperties', $property); } }); } public static function getComputedProperties($target) { return collect(static::getComputedPropertyNames($target)) ->mapWithKeys(function ($property) use ($target) { return [$property => static::getComputedProperty($target, $property)]; }) ->all(); } public static function hasComputedProperty($target, $property) { return array_search((string) str($property)->camel(), static::getComputedPropertyNames($target)) !== false; } public static function getComputedProperty($target, $property) { if (! static::hasComputedProperty($target, $property)) { throw new \Exception('No computed property found: $'.$property); } $method = 'get'.str($property)->studly().'Property'; store($target)->push( 'computedProperties', $value = store($target)->find('computedProperties', $property, fn() => wrap($target)->$method()), $property, ); return $value; } public static function getComputedPropertyNames($target) { $methodNames = SyntheticUtils::getPublicMethodsDefinedBySubClass($target); return collect($methodNames) ->filter(function ($method) { return str($method)->startsWith('get') && str($method)->endsWith('Property'); }) ->map(function ($method) { return (string) str($method)->between('get', 'Property')->camel(); }) ->all(); } } livewire/src/Features/SupportComputed/CannotCallComputedDirectlyException.php 0000644 00000000534 15060132176 0023726 0 ustar 00 <?php namespace Livewire\Features\SupportComputed; use Exception; class CannotCallComputedDirectlyException extends Exception { function __construct($componentName, $methodName) { parent::__construct( "Cannot call [{$methodName}()] computed property method directly on component: {$componentName}" ); } } livewire/src/Features/SupportLazyLoading/SupportLazyLoading.php 0000644 00000012404 15060132176 0021076 0 ustar 00 <?php namespace Livewire\Features\SupportLazyLoading; use Livewire\Features\SupportLifecycleHooks\SupportLifecycleHooks; use Livewire\Mechanisms\HandleComponents\ViewContext; use function Livewire\{ on, store, trigger, wrap }; use Illuminate\Routing\Route; use Livewire\ComponentHook; use Livewire\Drawer\Utils; use Livewire\Component; class SupportLazyLoading extends ComponentHook { static $disableWhileTesting = false; static function disableWhileTesting() { static::$disableWhileTesting = true; } static function provide() { static::registerRouteMacro(); on('flush-state', function () { static::$disableWhileTesting = false; }); } static function registerRouteMacro() { Route::macro('lazy', function ($enabled = true) { $this->defaults['lazy'] = $enabled; return $this; }); } public function mount($params) { $hasLazyParam = isset($params['lazy']); $lazyProperty = $params['lazy'] ?? false; $isolate = true; $reflectionClass = new \ReflectionClass($this->component); $lazyAttribute = $reflectionClass->getAttributes(\Livewire\Attributes\Lazy::class)[0] ?? null; // If Livewire::withoutLazyLoading()... if (static::$disableWhileTesting) return; // If `:lazy="false"` disable lazy loading... if ($hasLazyParam && ! $lazyProperty) return; // If no lazy loading is included at all... if (! $hasLazyParam && ! $lazyAttribute) return; if ($lazyAttribute) { $attribute = $lazyAttribute->newInstance(); $isolate = $attribute->isolate; } $this->component->skipMount(); store($this->component)->set('isLazyLoadMounting', true); store($this->component)->set('isLazyIsolated', $isolate); $this->component->skipRender( $this->generatePlaceholderHtml($params) ); } public function hydrate($memo) { if (! isset($memo['lazyLoaded'])) return; if ($memo['lazyLoaded'] === true) return; $this->component->skipHydrate(); store($this->component)->set('isLazyLoadHydrating', true); } function dehydrate($context) { if (store($this->component)->get('isLazyLoadMounting') === true) { $context->addMemo('lazyLoaded', false); $context->addMemo('lazyIsolated', store($this->component)->get('isLazyIsolated')); } elseif (store($this->component)->get('isLazyLoadHydrating') === true) { $context->addMemo('lazyLoaded', true); } } function call($method, $params, $returnEarly) { if ($method !== '__lazyLoad') return; [ $encoded ] = $params; $mountParams = $this->resurrectMountParams($encoded); $this->callMountLifecycleMethod($mountParams); $returnEarly(); } public function generatePlaceholderHtml($params) { $this->registerContainerComponent(); $container = app('livewire')->new('__mountParamsContainer'); $container->forMount = array_diff_key($params, array_flip(['lazy'])); $snapshot = app('livewire')->snapshot($container); $encoded = base64_encode(json_encode($snapshot)); $placeholder = $this->getPlaceholderView($this->component, $params); $finish = trigger('render.placeholder', $this->component, $placeholder, $params); $viewContext = new ViewContext; $html = $placeholder->render(function ($view) use ($viewContext) { // Extract leftover slots, sections, and pushes before they get flushed... $viewContext->extractFromEnvironment($view->getFactory()); }); $html = Utils::insertAttributesIntoHtmlRoot($html, [ ((isset($params['lazy']) and $params['lazy'] === 'on-load') ? 'x-init' : 'x-intersect') => '$wire.__lazyLoad(\''.$encoded.'\')', ]); $replaceHtml = function ($newHtml) use (&$html) { $html = $newHtml; }; $html = $finish($html, $replaceHtml, $viewContext); return $html; } protected function getPlaceholderView($component, $params) { $globalPlaceholder = config('livewire.lazy_placeholder'); $placeholderHtml = $globalPlaceholder ? view($globalPlaceholder)->render() : '<div></div>'; $viewOrString = wrap($component)->withFallback($placeholderHtml)->placeholder($params); $properties = Utils::getPublicPropertiesDefinedOnSubclass($component); $view = Utils::generateBladeView($viewOrString, $properties); return $view; } function resurrectMountParams($encoded) { $snapshot = json_decode(base64_decode($encoded), associative: true); $this->registerContainerComponent(); [ $container ] = app('livewire')->fromSnapshot($snapshot); return $container->forMount; } function callMountLifecycleMethod($params) { $hook = new SupportLifecycleHooks; $hook->setComponent($this->component); $hook->mount($params); } public function registerContainerComponent() { app('livewire')->component('__mountParamsContainer', new class extends Component { public $forMount; }); } } livewire/src/Features/SupportLazyLoading/BaseLazy.php 0000644 00000000437 15060132176 0017001 0 ustar 00 <?php namespace Livewire\Features\SupportLazyLoading; use Livewire\Features\SupportAttributes\Attribute as LivewireAttribute; #[\Attribute(\Attribute::TARGET_CLASS)] class BaseLazy extends LivewireAttribute { public function __construct( public $isolate = true ) {} } livewire/src/Features/SupportLocales/SupportLocales.php 0000644 00000000521 15060132176 0017405 0 ustar 00 <?php namespace Livewire\Features\SupportLocales; use Livewire\ComponentHook; class SupportLocales extends ComponentHook { function hydrate($memo) { if ($locale = $memo['locale']) app()->setLocale($locale); } function dehydrate($context) { $context->addMemo('locale', app()->getLocale()); } } livewire/src/Features/SupportMultipleRootElementDetection/MultipleRootElementsDetectedException.php 0000644 00000000653 15060132176 0030337 0 ustar 00 <?php namespace Livewire\Features\SupportMultipleRootElementDetection; use Livewire\Exceptions\BypassViewHandler; class MultipleRootElementsDetectedException extends \Exception { use BypassViewHandler; function __construct($component) { parent::__construct('Livewire only supports one HTML element per component. Multiple root elements detected for component: [' . $component->getName() . ']'); } } livewire/src/Features/SupportMultipleRootElementDetection/SupportMultipleRootElementDetection.php 0000644 00000002233 15060132176 0030063 0 ustar 00 <?php namespace Livewire\Features\SupportMultipleRootElementDetection; use Livewire\ComponentHook; use function Livewire\on; class SupportMultipleRootElementDetection extends ComponentHook { static function provide() { on('mount', function ($component) { if (! config('app.debug')) return; return function ($html) use ($component) { (new static)->warnAgainstMoreThanOneRootElement($component, $html); }; }); } function warnAgainstMoreThanOneRootElement($component, $html) { $count = $this->getRootElementCount($html); if ($count > 1) { throw new MultipleRootElementsDetectedException($component); } } function getRootElementCount($html) { $dom = new \DOMDocument(); @$dom->loadHTML($html); $body = $dom->getElementsByTagName('body')->item(0); $count = 0; foreach ($body->childNodes as $child) { if ($child->nodeType == XML_ELEMENT_NODE) { if ($child->tagName === 'script') continue; $count++; } } return $count; } } livewire/src/Features/SupportModels/SupportModels.php 0000644 00000000456 15060132176 0017116 0 ustar 00 <?php namespace Livewire\Features\SupportModels; use Livewire\ComponentHook; class SupportModels extends ComponentHook { static function provide() { app('livewire')->propertySynthesizer([ ModelSynth::class, EloquentCollectionSynth::class, ]); } } livewire/src/Features/SupportModels/EloquentCollectionSynth.php 0000644 00000005355 15060132176 0021137 0 ustar 00 <?php namespace Livewire\Features\SupportModels; use Illuminate\Database\Eloquent\Collection as EloquentCollection; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Queue\SerializesAndRestoresModelIdentifiers; use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth; class EloquentCollectionSynth extends Synth { use SerializesAndRestoresModelIdentifiers; public static $key = 'elcln'; static function match($target) { return $target instanceof EloquentCollection; } function dehydrate(EloquentCollection $target, $dehydrateChild) { $class = $target::class; $modelClass = $target->getQueueableClass(); /** * `getQueueableClass` above checks all models are the same and * then returns the class. We then instantiate a model object * so we can call `getMorphClass()` on it. * * If no alias is found, this just returns the class name */ $modelAlias = $modelClass ? (new $modelClass)->getMorphClass() : null; $meta = []; $serializedCollection = (array) $this->getSerializedPropertyValue($target); $meta['keys'] = $serializedCollection['id']; $meta['class'] = $class; $meta['modelClass'] = $modelAlias; return [ null, $meta ]; } function hydrate($data, $meta, $hydrateChild) { $class = $meta['class']; $modelClass = $meta['modelClass']; // If no alias found, this returns `null` $modelAlias = Relation::getMorphedModel($modelClass); if (! is_null($modelAlias)) { $modelClass = $modelAlias; } $keys = $meta['keys'] ?? []; if (count($keys) === 0) { return new $class(); } // We are using Laravel's method here for restoring the collection, which ensures // that all models in the collection are restored in one query, preventing n+1 // issues and also only restores models that exist. $collection = (new $modelClass)->newQueryForRestoration($keys)->useWritePdo()->get(); $collection = $collection->keyBy->getKey(); return new $meta['class']( collect($meta['keys'])->map(function ($id) use ($collection) { return $collection[$id] ?? null; })->filter() ); } function get(&$target, $key) { throw new \Exception('Can\'t access model properties directly'); } function set(&$target, $key, $value, $pathThusFar, $fullPath) { throw new \Exception('Can\'t set model properties directly'); } function call($target, $method, $params, $addEffect) { throw new \Exception('Can\'t call model methods directly'); } } livewire/src/Features/SupportModels/ModelSynth.php 0000644 00000004422 15060132176 0016361 0 ustar 00 <?php namespace Livewire\Features\SupportModels; use Illuminate\Database\ClassMorphViolationException; use Illuminate\Database\Eloquent\Relations\Relation; use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth; use Illuminate\Queue\SerializesAndRestoresModelIdentifiers; use Illuminate\Database\Eloquent\Model; class ModelSynth extends Synth { use SerializesAndRestoresModelIdentifiers; public static $key = 'mdl'; static function match($target) { return $target instanceof Model; } function dehydrate($target) { $class = $target::class; try { // If no alias is found, this just returns the class name $alias = $target->getMorphClass(); } catch (ClassMorphViolationException $e) { // If the model is not using morph classes, this exception is thrown $alias = $class; } $serializedModel = $target->exists ? (array) $this->getSerializedPropertyValue($target) : null; $meta = ['class' => $alias]; // If the model doesn't exist as it's an empty model or has been // recently deleted, then we don't want to include any key. if ($serializedModel) $meta['key'] = $serializedModel['id']; return [ null, $meta, ]; } function hydrate($data, $meta) { $class = $meta['class']; // If no alias found, this returns `null` $aliasClass = Relation::getMorphedModel($class); if (! is_null($aliasClass)) { $class = $aliasClass; } // If no key is provided then an empty model is returned if (! array_key_exists('key', $meta)) { return new $class; } $key = $meta['key']; $model = (new $class)->newQueryForRestoration($key)->useWritePdo()->firstOrFail(); return $model; } function get(&$target, $key) { throw new \Exception('Can\'t access model properties directly'); } function set(&$target, $key, $value, $pathThusFar, $fullPath) { throw new \Exception('Can\'t set model properties directly'); } function call($target, $method, $params, $addEffect) { throw new \Exception('Can\'t call model methods directly'); } } livewire/src/Features/SupportFormObjects/Form.php 0000644 00000011030 15060132176 0016161 0 ustar 00 <?php namespace Livewire\Features\SupportFormObjects; use Livewire\Features\SupportValidation\HandlesValidation; use Illuminate\Validation\ValidationException; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\MessageBag; use function Livewire\invade; use Illuminate\Support\Arr; use Livewire\Drawer\Utils; use Livewire\Component; class Form implements Arrayable { use HandlesValidation { validate as parentValidate; validateOnly as parentValidateOnly; } function __construct( protected Component $component, protected $propertyName ) {} public function getComponent() { return $this->component; } public function getPropertyName() { return $this->propertyName; } public function validate($rules = null, $messages = [], $attributes = []) { try { return $this->parentValidate($rules, $messages, $attributes); } catch (ValidationException $e) { invade($e->validator)->messages = $this->prefixErrorBag(invade($e->validator)->messages); invade($e->validator)->failedRules = $this->prefixArray(invade($e->validator)->failedRules); throw $e; } } public function validateOnly($field, $rules = null, $messages = [], $attributes = [], $dataOverrides = []) { try { return $this->parentValidateOnly($field, $rules, $messages, $attributes, $dataOverrides); } catch (ValidationException $e) { invade($e->validator)->messages = $this->prefixErrorBag(invade($e->validator)->messages)->merge( $this->getComponent()->getErrorBag() ); invade($e->validator)->failedRules = $this->prefixArray(invade($e->validator)->failedRules); throw $e; } } protected function runSubValidators() { // This form object IS the sub-validator. // Let's skip it... } protected function prefixErrorBag($bag) { $raw = $bag->toArray(); $raw = Arr::prependKeysWith($raw, $this->getPropertyName().'.'); return new MessageBag($raw); } protected function prefixArray($array) { return Arr::prependKeysWith($array, $this->getPropertyName().'.'); } public function addError($key, $message) { $this->component->addError($this->propertyName . '.' . $key, $message); } public function resetErrorBag($field = null) { $fields = (array) $field; foreach ($fields as $idx => $field) { $fields[$idx] = $this->propertyName . '.' . $field; } $this->getComponent()->resetErrorBag($fields); } public function all() { return $this->toArray(); } public function only($properties) { $results = []; foreach (is_array($properties) ? $properties : func_get_args() as $property) { $results[$property] = $this->hasProperty($property) ? $this->getPropertyValue($property) : null; } return $results; } public function except($properties) { $properties = is_array($properties) ? $properties : func_get_args(); return array_diff_key($this->all(), array_flip($properties)); } public function hasProperty($prop) { return property_exists($this, Utils::beforeFirstDot($prop)); } public function getPropertyValue($name) { $value = $this->{Utils::beforeFirstDot($name)}; if (Utils::containsDots($name)) { return data_get($value, Utils::afterFirstDot($name)); } return $value; } public function fill($values) { $publicProperties = array_keys($this->all()); if ($values instanceof Model) { $values = $values->toArray(); } foreach ($values as $key => $value) { if (in_array(Utils::beforeFirstDot($key), $publicProperties)) { data_set($this, $key, $value); } } } public function reset(...$properties) { $properties = count($properties) && is_array($properties[0]) ? $properties[0] : $properties; if (empty($properties)) $properties = array_keys($this->all()); $freshInstance = new static($this->getComponent(), $this->getPropertyName()); foreach ($properties as $property) { data_set($this, $property, data_get($freshInstance, $property)); } } public function toArray() { return Utils::getPublicProperties($this); } } livewire/src/Features/SupportFormObjects/SupportFormObjects.php 0000644 00000002557 15060132176 0021106 0 ustar 00 <?php namespace Livewire\Features\SupportFormObjects; use ReflectionClass; use Livewire\ComponentHook; use ReflectionNamedType; use function Livewire\on; class SupportFormObjects extends ComponentHook { public static function provide() { app('livewire')->propertySynthesizer( FormObjectSynth::class ); } function boot() { $this->initializeFormObjects(); } protected function initializeFormObjects() { foreach ((new ReflectionClass($this->component))->getProperties() as $property) { // Public properties only... if ($property->isPublic() !== true) continue; // Uninitialized properties only... if ($property->isInitialized($this->component)) continue; $type = $property->getType(); if (! $type instanceof ReflectionNamedType) continue; $typeName = $type->getName(); // "Form" object property types only... if (! is_subclass_of($typeName, Form::class)) continue; $form = new $typeName( $this->component, $name = $property->getName() ); $callBootMethod = FormObjectSynth::bootFormObject($this->component, $form, $name); $property->setValue($this->component, $form); $callBootMethod(); } } } livewire/src/Features/SupportFormObjects/HandlesFormObjects.php 0000644 00000000514 15060132176 0020777 0 ustar 00 <?php namespace Livewire\Features\SupportFormObjects; trait HandlesFormObjects { public function getFormObjects() { $forms = []; foreach ($this->all() as $key => $value) { if ($value instanceof Form) { $forms[] = $value; } } return $forms; } } livewire/src/Features/SupportFormObjects/FormObjectSynth.php 0000644 00000003266 15060132176 0020352 0 ustar 00 <?php namespace Livewire\Features\SupportFormObjects; use Livewire\Drawer\Utils; use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth; use Livewire\Features\SupportAttributes\AttributeCollection; use function Livewire\wrap; class FormObjectSynth extends Synth { public static $key = 'form'; static function match($target) { return $target instanceof Form; } function dehydrate($target, $dehydrateChild) { $data = $target->toArray(); foreach ($data as $key => $child) { $data[$key] = $dehydrateChild($key, $child); } return [$data, ['class' => get_class($target)]]; } function hydrate($data, $meta, $hydrateChild) { $form = new $meta['class']($this->context->component, $this->path); $callBootMethod = static::bootFormObject($this->context->component, $form, $this->path); foreach ($data as $key => $child) { if ($child === null && Utils::propertyIsTypedAndUninitialized($form, $key)) { continue; } $form->$key = $hydrateChild($key, $child); } $callBootMethod(); return $form; } function set(&$target, $key, $value) { if ($value === null && Utils::propertyIsTyped($target, $key)) { unset($target->$key); } else { $target->$key = $value; } } public static function bootFormObject($component, $form, $path) { $component->mergeOutsideAttributes( AttributeCollection::fromComponent($component, $form, $path . '.') ); return function () use ($form) { wrap($form)->boot(); }; } } livewire/src/Features/SupportTeleporting/SupportTeleporting.php 0000644 00000000727 15060132176 0021241 0 ustar 00 <?php namespace Livewire\Features\SupportTeleporting; use Illuminate\Support\Facades\Blade; use Livewire\ComponentHook; class SupportTeleporting extends ComponentHook { static function provide() { Blade::directive('teleport', function ($expression) { return '<template x-teleport="<?php echo e('.$expression.'); ?>">'; }); Blade::directive('endteleport', function () { return '</template>'; }); } } livewire/src/Features/SupportLifecycleHooks/SupportLifecycleHooks.php 0000644 00000011146 15060132176 0022254 0 ustar 00 <?php namespace Livewire\Features\SupportLifecycleHooks; use function Livewire\store; use function Livewire\wrap; use Livewire\ComponentHook; class SupportLifecycleHooks extends ComponentHook { public function mount($params) { if (store($this->component)->has('skipMount')) { return; } $this->callHook('boot'); $this->callTraitHook('boot'); $this->callTraitHook('initialize'); $this->callHook('mount', $params); $this->callTraitHook('mount', $params); $this->callHook('booted'); $this->callTraitHook('booted'); } public function hydrate() { if (store($this->component)->has('skipHydrate')) { return; } $this->callHook('boot'); $this->callTraitHook('boot'); $this->callTraitHook('initialize'); $this->callHook('hydrate'); $this->callTraitHook('hydrate'); // Call "hydrateXx" hooks for each property... foreach ($this->getProperties() as $property => $value) { $this->callHook('hydrate'.str($property)->studly(), [$value]); } $this->callHook('booted'); $this->callTraitHook('booted'); } public function update($propertyName, $fullPath, $newValue) { $name = str($fullPath); $propertyName = $name->studly()->before('.'); $keyAfterFirstDot = $name->contains('.') ? $name->after('.')->__toString() : null; $keyAfterLastDot = $name->contains('.') ? $name->afterLast('.')->__toString() : null; $beforeMethod = 'updating'.$propertyName; $afterMethod = 'updated'.$propertyName; $beforeNestedMethod = $name->contains('.') ? 'updating'.$name->replace('.', '_')->studly() : false; $afterNestedMethod = $name->contains('.') ? 'updated'.$name->replace('.', '_')->studly() : false; $this->callHook('updating', [$fullPath, $newValue]); $this->callTraitHook('updating', [$fullPath, $newValue]); $this->callHook($beforeMethod, [$newValue, $keyAfterFirstDot]); $this->callHook($beforeNestedMethod, [$newValue, $keyAfterLastDot]); return function () use ($fullPath, $afterMethod, $afterNestedMethod, $keyAfterFirstDot, $keyAfterLastDot, $newValue) { $this->callHook('updated', [$fullPath, $newValue]); $this->callTraitHook('updated', [$fullPath, $newValue]); $this->callHook($afterMethod, [$newValue, $keyAfterFirstDot]); $this->callHook($afterNestedMethod, [$newValue, $keyAfterLastDot]); }; } public function call($methodName, $params, $returnEarly) { $protectedMethods = [ 'mount', 'exception', 'hydrate*', 'dehydrate*', 'updating*', 'updated*', ]; throw_if( str($methodName)->is($protectedMethods), new DirectlyCallingLifecycleHooksNotAllowedException($methodName, $this->component->getName()) ); $this->callTraitHook('call', ['methodName' => $methodName, 'params' => $params, 'returnEarly' => $returnEarly]); } public function exception($e, $stopPropagation) { $this->callHook('exception', ['e' => $e, 'stopPropagation' => $stopPropagation]); $this->callTraitHook('exception', ['e' => $e, 'stopPropagation' => $stopPropagation]); } public function render($view, $data) { $this->callHook('rendering', ['view' => $view, 'data' => $data]); $this->callTraitHook('rendering', ['view' => $view, 'data' => $data]); return function ($html) use ($view) { $this->callHook('rendered', ['view' => $view, 'html' => $html]); $this->callTraitHook('rendered', ['view' => $view, 'html' => $html]); }; } public function dehydrate() { $this->callHook('dehydrate'); $this->callTraitHook('dehydrate'); // Call "dehydrateXx" hooks for each property... foreach ($this->getProperties() as $property => $value) { $this->callHook('dehydrate'.str($property)->studly(), [$value]); } } public function callHook($name, $params = []) { if (method_exists($this->component, $name)) { wrap($this->component)->__call($name, $params); } } function callTraitHook($name, $params = []) { foreach (class_uses_recursive($this->component) as $trait) { $method = $name.class_basename($trait); if (method_exists($this->component, $method)) { wrap($this->component)->$method(...$params); } } } } livewire/src/Features/SupportLifecycleHooks/DirectlyCallingLifecycleHooksNotAllowedException.php 0000644 00000000632 15060132176 0027517 0 ustar 00 <?php namespace Livewire\Features\SupportLifecycleHooks; use Livewire\Exceptions\BypassViewHandler; class DirectlyCallingLifecycleHooksNotAllowedException extends \Exception { use BypassViewHandler; public function __construct($method, $component) { parent::__construct( "Unable to call lifecycle method [{$method}] directly on component: [{$component}]" ); } } livewire/src/Features/SupportWireLoading/browser_test_image.png 0000644 00000005275 15060132176 0021144 0 ustar 00 �PNG IHDR � < ���� aiCCPkCGColorSpaceDisplayP3 (�c``RI,(�aa``��+) rwR���R`���b ����>@%0|���/��:%5�I�^��b��Ջ�D�0գ ����d ��S��JS�l����): Ȟb�C�@�$�XMH�3�}�VH�H�����IBOGbC�n��ₜ�J� c�%��V��h�ʢ��G`(�*x�%��(�30����s 8,�� Ě�30����n���~��@�\;b��'v$%�����)-����r�H�@=��i�F`yF'�{��Vc``���w������w1P��y !e�5�� �eXIfMM * > F( �i N � � �� x� ؠ <