Comments (3)
/** @extends Form<SomeModel> */
Very cool and elegant 💪
from laminas-form.
Hopefully the psalm bot is working here. This is what I have in mind:
https://psalm.dev/r/0d6f0ee752
from laminas-form.
I found these snippets:
https://psalm.dev/r/0d6f0ee752
<?php
/**
* @template TValues
*/
interface Filter {
/** @return TValues */
public function getValues(): array;
}
/**
* @psalm-type MyPayload = array{
* foo: non-empty-string,
* }
* @implements Filter<MyPayload>
*/
class MyFilter implements Filter {
public function getValues(): array
{
return ['foo' => 'bar'];
}
}
/** @template TFilterShape */
interface Form
{
/** @return TFilterShape */
public function getData(): array;
/** @param Filter<TFilterShape> $filter **/
public function setFilter(Filter $filter): void;
}
/**
* @template TFilterShape
* @implements Form<TFilterShape>
*/
abstract class BaseForm implements Form
{
/** @var Filter<TFilterShape> */
private Filter|null $filter = null;
/** @return TFilterShape */
public function getData(): array
{
if (! $this->filter) { throw new Exception('Bad News'); }
return $this->filter->getValues();
}
/** @param Filter<TFilterShape> $filter **/
public function setFilter(Filter $filter): void
{
$this->filter = $filter;
}
}
/**
* @psalm-import-type MyPayload from MyFilter
* @extends BaseForm<MyPayload>
*/
class MyForm extends BaseForm
{
}
$form = new MyForm();
$form->setFilter(new MyFilter());
$foo = $form->getData()['foo'];
/** @psalm-trace $foo */
Psalm output (using commit baa6d5d):
INFO: Trace - 72:25 - $foo: non-empty-string
INFO: UnusedVariable - 70:1 - $foo is never referenced or the value is not used
from laminas-form.
Related Issues (20)
- After update from 2.17 to 3.1.1: Nested fieldset results in TypeError: template is undefined HOT 3
- Problems in tests with collections and setValidationGroup() HOT 3
- FormAttributeBuilder exception break on php 7.4 HOT 9
- Github pages isn't working( HOT 7
- Dependency Dashboard
- Add onfocusout on $validGlobalAttributes HOT 1
- ComposedObject annotation doesn't work with Required(false)
- Can't require latest package version when using PHP 8.0 running composer HOT 4
- Ability to wrap element for complex form rendering HOT 4
- Bug of day 31 (Element\Month) HOT 4
- keys(option-values) generation in get(Hours|Minutes|Seconds|...)Options HOT 3
- DateTime related elements should accept DateTimeInterface values HOT 1
- Date pattern parsing fails with "exotic" locales HOT 6
- Date/Time selects helpers __invoke args may have no effect
- IntlDateFormatter::SHORT is not handled correctly by date-time select helper HOT 1
- \Laminas\Form\View\Helper\FormSelect does not allow class attribute for <option>s HOT 2
- FormMultiCheckbox doesn't render zero as hidden element HOT 2
- Problem with different Renderer HOT 6
- DateTimeLocal considers the "step" attribute to be minutes, when the HTML element specification asserts that it is seconds HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laminas-form.