Skip to content

Commit 4d0cc0f

Browse files
committed
Replaced call to AsLiveComponent::getMethod
1 parent d7fdcd7 commit 4d0cc0f

File tree

5 files changed

+11
-27
lines changed

5 files changed

+11
-27
lines changed

src/LiveComponent/src/Attribute/AsLiveComponent.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,4 @@ public static function liveListeners(object|string $component): array
124124

125125
return $listeners;
126126
}
127-
128-
public static function getMethod(object|string $component): string
129-
{
130-
$attributes = (new \ReflectionClass($component))->getAttributes(self::class);
131-
132-
return $attributes[0]->newInstance()->serviceConfig()['method'] ?? 'post';
133-
}
134127
}

src/LiveComponent/src/EventListener/LiveComponentSubscriber.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ public function onKernelController(ControllerEvent $event): void
164164
throw new NotFoundHttpException(sprintf('The action "%s" either doesn\'t exist or is not allowed in "%s". Make sure it exist and has the LiveAction attribute above it.', $action, $component::class));
165165
}
166166

167-
$requestMethod = AsLiveComponent::getMethod($component);
167+
$componentName = $request->attributes->get('_component_name') ?? $request->attributes->get('_mounted_component')->getName();
168+
$requestMethod = $this->container->get(ComponentFactory::class)->metadataFor($componentName)?->get('method') ?? 'post';
168169

169170
/**
170171
* $requestMethod 'post' allows POST requests only

src/LiveComponent/src/Util/LiveControllerAttributesCreator.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,9 @@ public function attributesForRendering(MountedComponent $mounted, ComponentMetad
9898
$mountedAttributes = $mountedAttributes->defaults(['data-live-id' => $id]);
9999
}
100100

101-
<<<<<<< HEAD
102-
$requestMethod = AsLiveComponent::getMethod($mounted->getComponent());
103-
104-
if (!isset($mountedAttributes->all()['data-live-request-method-value'])) {
105-
$attributesCollection->setRequestMethod($requestMethod);
106-
$mountedAttributes = $mountedAttributes->defaults(['data-live-request-method-value' => $requestMethod]);
107-
=======
108101
$liveMetadata = $this->metadataFactory->getMetadata($mounted->getName());
102+
$requestMethod = $liveMetadata->getComponentMetadata()?->get('method') ?? 'post';
103+
$attributesCollection->setRequestMethod($requestMethod);
109104

110105
if ($liveMetadata->hasQueryStringBindings()) {
111106
$queryMapping = [];
@@ -116,7 +111,6 @@ public function attributesForRendering(MountedComponent $mounted, ComponentMetad
116111
}
117112
}
118113
$attributesCollection->setQueryUrlMapping($queryMapping);
119-
>>>>>>> upstream/2.x
120114
}
121115

122116
if ($isChildComponent) {

src/LiveComponent/tests/Functional/Controller/BatchActionControllerTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,13 @@ public function testRedirectWithAcceptHeader(): void
178178

179179
$this->browser()
180180
->throwExceptions()
181-
->get('/_components/with_actions', ['query' => ['props' => json_encode($dehydrated->getProps())]])
181+
->post('/_components/with_actions', [
182+
'body' => [
183+
'data' => json_encode([
184+
'props' => $dehydrated->getProps()
185+
]),
186+
],
187+
])
182188
->assertSuccessful()
183189
->interceptRedirects()
184190
->use(function (Crawler $crawler, KernelBrowser $browser) {

src/LiveComponent/tests/Unit/Attribute/AsLiveComponentTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,6 @@ public function testCanCheckIfMethodIsAllowed(): void
145145
$this->assertFalse(AsLiveComponent::isActionAllowed($component, 'method2'));
146146
$this->assertTrue(AsLiveComponent::isActionAllowed($component, 'aListenerActionMethod'));
147147
}
148-
149-
public function testMethodDefaultsToPost(): void
150-
{
151-
$this->assertEquals('post', AsLiveComponent::getMethod(DummyLiveComponent::class));
152-
}
153-
154-
public function testGetMethod(): void
155-
{
156-
$this->assertEquals('get', AsLiveComponent::getMethod(GetMethodComponent::class));
157-
}
158148
}
159149

160150
#[AsLiveComponent]

0 commit comments

Comments
 (0)