Skip to content

Commit 56284a8

Browse files
committed
used first-class callables
1 parent 5aa749c commit 56284a8

14 files changed

+53
-53
lines changed

best-practices/cs/creating-editing-form.texy

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class RecordPresenter extends Nette\Application\UI\Presenter
2929

3030
// ... přidáme políčka formuláře ...
3131

32-
$form->onSuccess[] = [$this, 'recordFormSucceeded'];
32+
$form->onSuccess[] = $this->recordFormSucceeded(...);
3333
return $form;
3434
}
3535

36-
public function recordFormSucceeded(Form $form, array $data): void
36+
private function recordFormSucceeded(Form $form, array $data): void
3737
{
3838
$this->facade->add($data); // přidání záznamu do databáze
3939
$this->flashMessage('Successfully added');
@@ -91,11 +91,11 @@ class RecordPresenter extends Nette\Application\UI\Presenter
9191
// ... přidáme políčka formuláře ...
9292

9393
$form->setDefaults($this->record); // nastavení výchozích hodnot
94-
$form->onSuccess[] = [$this, 'recordFormSucceeded'];
94+
$form->onSuccess[] = $this->recordFormSucceeded(...);
9595
return $form;
9696
}
9797

98-
public function recordFormSucceeded(Form $form, array $data): void
98+
private function recordFormSucceeded(Form $form, array $data): void
9999
{
100100
$this->facade->update($this->record->id, $data); // aktualizace záznamu
101101
$this->flashMessage('Successfully updated');
@@ -153,7 +153,7 @@ class RecordPresenter extends Nette\Application\UI\Presenter
153153
public function actionAdd(): void
154154
{
155155
$form = $this->getComponent('recordForm');
156-
$form->onSuccess[] = [$this, 'addingFormSucceeded'];
156+
$form->onSuccess[] = $this->addingFormSucceeded(...);
157157
}
158158

159159
public function actionEdit(int $id): void
@@ -168,7 +168,7 @@ class RecordPresenter extends Nette\Application\UI\Presenter
168168

169169
$form = $this->getComponent('recordForm');
170170
$form->setDefaults($record); // nastavení výchozích hodnot
171-
$form->onSuccess[] = [$this, 'editingFormSucceeded'];
171+
$form->onSuccess[] = $this->editingFormSucceeded(...);
172172
}
173173

174174
protected function createComponentRecordForm(): Form
@@ -185,14 +185,14 @@ class RecordPresenter extends Nette\Application\UI\Presenter
185185
return $form;
186186
}
187187

188-
public function addingFormSucceeded(Form $form, array $data): void
188+
private function addingFormSucceeded(Form $form, array $data): void
189189
{
190190
$this->facade->add($data); // přidání záznamu do databáze
191191
$this->flashMessage('Successfully added');
192192
$this->redirect('...');
193193
}
194194

195-
public function editingFormSucceeded(Form $form, array $data): void
195+
private function editingFormSucceeded(Form $form, array $data): void
196196
{
197197
$id = (int) $this->getParameter('id');
198198
$this->facade->update($id, $data); // aktualizace záznamu

best-practices/cs/form-reuse.texy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ class EditFormFactory
193193
$form->addText('title', 'Titulek:');
194194
// zde se přidávají další formulářová pole
195195
$form->addSubmit('send', 'Odeslat');
196-
$form->onSuccess[] = [$this, 'processForm'];
196+
$form->onSuccess[] = $this->processForm(...);
197197
return $form;
198198
}
199199

200-
public function processForm(Form $form, array $data): void
200+
private function processForm(Form $form, array $data): void
201201
{
202202
try {
203203
// zpracování odeslaných dat
@@ -284,12 +284,12 @@ class EditControl extends Nette\Application\UI\Control
284284
$form->addText('title', 'Titulek:');
285285
// zde se přidávají další formulářová pole
286286
$form->addSubmit('send', 'Odeslat');
287-
$form->onSuccess[] = [$this, 'processForm'];
287+
$form->onSuccess[] = $this->processForm(...);
288288

289289
return $form;
290290
}
291291

292-
public function processForm(Form $form, array $data): void
292+
private function processForm(Form $form, array $data): void
293293
{
294294
try {
295295
// zpracování odeslaných dat

best-practices/cs/lets-create-contact-form.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class HomePresenter extends Presenter
2424
$form->addTextarea('message', 'Zpráva:')
2525
->setRequired('Zadejte zprávu');
2626
$form->addSubmit('send', 'Odeslat');
27-
$form->onSuccess[] = [$this, 'contactFormSucceeded'];
27+
$form->onSuccess[] = $this->contactFormSucceeded(...);
2828
return $form;
2929
}
3030

31-
public function contactFormSucceeded(Form $form, $data): void
31+
private function contactFormSucceeded(Form $form, $data): void
3232
{
3333
// odeslání emailu
3434
}

best-practices/cs/restore-request.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class SignPresenter extends Nette\Application\UI\Presenter
4141
{
4242
$form = new Nette\Application\UI\Form;
4343
// ... přidáme políčka formuláře ...
44-
$form->onSuccess[] = [$this, 'signInFormSubmitted'];
44+
$form->onSuccess[] = $this->signInFormSubmitted(...);
4545
return $form;
4646
}
4747

48-
public function signInFormSubmitted($form)
48+
private function signInFormSubmitted($form)
4949
{
5050
// ... tady uživatele přihlásíme ...
5151

best-practices/en/creating-editing-form.texy

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class RecordPresenter extends Nette\Application\UI\Presenter
2929

3030
// ... add form fields ...
3131

32-
$form->onSuccess[] = [$this, 'recordFormSucceeded'];
32+
$form->onSuccess[] = $this->recordFormSucceeded(...);
3333
return $form;
3434
}
3535

36-
public function recordFormSucceeded(Form $form, array $data): void
36+
private function recordFormSucceeded(Form $form, array $data): void
3737
{
3838
$this->facade->add($data); // add record to the database
3939
$this->flashMessage('Successfully added');
@@ -91,11 +91,11 @@ class RecordPresenter extends Nette\Application\UI\Presenter
9191
// ... add form fields ...
9292

9393
$form->setDefaults($this->record); // set default values
94-
$form->onSuccess[] = [$this, 'recordFormSucceeded'];
94+
$form->onSuccess[] = $this->recordFormSucceeded(...);
9595
return $form;
9696
}
9797

98-
public function recordFormSucceeded(Form $form, array $data): void
98+
private function recordFormSucceeded(Form $form, array $data): void
9999
{
100100
$this->facade->update($this->record->id, $data); // update record
101101
$this->flashMessage('Successfully updated');
@@ -153,7 +153,7 @@ class RecordPresenter extends Nette\Application\UI\Presenter
153153
public function actionAdd(): void
154154
{
155155
$form = $this->getComponent('recordForm');
156-
$form->onSuccess[] = [$this, 'addingFormSucceeded'];
156+
$form->onSuccess[] = $this->addingFormSucceeded(...);
157157
}
158158

159159
public function actionEdit(int $id): void
@@ -168,7 +168,7 @@ class RecordPresenter extends Nette\Application\UI\Presenter
168168

169169
$form = $this->getComponent('recordForm');
170170
$form->setDefaults($record); // set default values
171-
$form->onSuccess[] = [$this, 'editingFormSucceeded'];
171+
$form->onSuccess[] = $this->editingFormSucceeded(...);
172172
}
173173

174174
protected function createComponentRecordForm(): Form
@@ -185,14 +185,14 @@ class RecordPresenter extends Nette\Application\UI\Presenter
185185
return $form;
186186
}
187187

188-
public function addingFormSucceeded(Form $form, array $data): void
188+
private function addingFormSucceeded(Form $form, array $data): void
189189
{
190190
$this->facade->add($data); // add record to the database
191191
$this->flashMessage('Successfully added');
192192
$this->redirect('...');
193193
}
194194

195-
public function editingFormSucceeded(Form $form, array $data): void
195+
private function editingFormSucceeded(Form $form, array $data): void
196196
{
197197
$id = (int) $this->getParameter('id');
198198
$this->facade->update($id, $data); // update record

best-practices/en/form-reuse.texy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ class EditFormFactory
193193
$form->addText('title', 'Title:');
194194
// additional form fields are added here
195195
$form->addSubmit('send', 'Save');
196-
$form->onSuccess[] = [$this, 'processForm'];
196+
$form->onSuccess[] = $this->processForm(...);
197197
return $form;
198198
}
199199

200-
public function processForm(Form $form, array $data): void
200+
private function processForm(Form $form, array $data): void
201201
{
202202
try {
203203
// processing of submitted data
@@ -284,12 +284,12 @@ class EditControl extends Nette\Application\UI\Control
284284
$form->addText('title', 'Title:');
285285
// additional form fields are added here
286286
$form->addSubmit('send', 'Save');
287-
$form->onSuccess[] = [$this, 'processForm'];
287+
$form->onSuccess[] = $this->processForm(...);
288288

289289
return $form;
290290
}
291291

292-
public function processForm(Form $form, array $data): void
292+
private function processForm(Form $form, array $data): void
293293
{
294294
try {
295295
// processing of submitted data

best-practices/en/lets-create-contact-form.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class HomePresenter extends Presenter
2424
$form->addTextarea('message', 'Message:')
2525
->setRequired('Please enter a message');
2626
$form->addSubmit('send', 'Send');
27-
$form->onSuccess[] = [$this, 'contactFormSucceeded'];
27+
$form->onSuccess[] = $this->contactFormSucceeded(...);
2828
return $form;
2929
}
3030

31-
public function contactFormSucceeded(Form $form, $data): void
31+
private function contactFormSucceeded(Form $form, $data): void
3232
{
3333
// sending an email
3434
}

best-practices/en/restore-request.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class SignPresenter extends Nette\Application\UI\Presenter
4141
{
4242
$form = new Nette\Application\UI\Form;
4343
// ... add form fields ...
44-
$form->onSuccess[] = [$this, 'signInFormSubmitted'];
44+
$form->onSuccess[] = $this->signInFormSubmitted(...);
4545
return $form;
4646
}
4747

48-
public function signInFormSubmitted($form)
48+
private function signInFormSubmitted($form)
4949
{
5050
// ... log the user in here ...
5151

dependency-injection/cs/services.texy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function createServiceFoo(): Foo
181181
{
182182
$service = new Foo;
183183
$service->value = 123;
184-
$service->onClick[] = [$this->getService('bar'), 'clickHandler'];
184+
$service->onClick[] = $this->getService('bar')->clickHandler(...);
185185
return $service;
186186
}
187187
```

dependency-injection/en/services.texy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function createServiceFoo(): Foo
181181
{
182182
$service = new Foo;
183183
$service->value = 123;
184-
$service->onClick[] = [$this->getService('bar'), 'clickHandler'];
184+
$service->onClick[] = $this->getService('bar')->clickHandler(...);
185185
return $service;
186186
}
187187
```

0 commit comments

Comments
 (0)