Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112139 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22083 invoked from network); 28 Oct 2020 18:38:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Oct 2020 18:38:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3FE191804CC for ; Wed, 28 Oct 2020 10:57:18 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 28 Oct 2020 10:57:17 -0700 (PDT) Received: by mail-wm1-f44.google.com with SMTP id t3so139397wmi.3 for ; Wed, 28 Oct 2020 10:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=0pKJ49lp9WP5E84ppRD70LjqoKhuaFQQ5/8GqqXXiMA=; b=jiAxd+SJaQIVwFj7PP0qrdvyQf/n9MOboRtCRtV/c8QRRcc/X516EbDZ0V5ZhpznHa ExXYN6gsa67pnLfdbKaghHkAegO0VufX5WJJXKvZFKcY695rKAXfermbbsAC6IRE/i1L P4YN4ZKR3F7+k4AYZTvPkEzhb+Vwtmao3eSdmRGqqGKNYvV95oTdLkKGVQm1RAx6GcWp 2sWstxo0nd15Ao94W9tLWDPYA5B6g1FyakFUMCZAOtVLFIEdk7uCNcAvGUFHRTcocNhd L7vVs4EE/A1NuIj+40PDtBLgVYrVgEfDzGBE8al1Ba/QKZSrF6mkOhsRiKlfwLdM+rNI WpQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=0pKJ49lp9WP5E84ppRD70LjqoKhuaFQQ5/8GqqXXiMA=; b=ZdXLKDG1CNRAhA+BhIzz3Dvhz7PYnWC8Jld+WdDXQLMntBS92i/UmODMZDTanVJYJs lIzauH2LACB53/VEmKd9KOwQq9BPY10cgm9IJ/Y/MFFO9oPF48BrPxlpEttD9oxjPbw1 SvHr1pIebXE60IvSupPpmXWZLLiv0YrIQZN92/AFUPDgTGwwtJCQLQgbqNKjknCxV+5b be0gDGtBZ6LOk9qRi5K54c5F/k+q0wFEzKqAPLWMq06n3QzA3CvM/t6cD8Phv3ajCrvj KS3Aa+WcwciBwf3aWV714+tybNuMwjrix5RBj2Ocfk3yClZNRTXXniba+zrVZ56AuW8P w1Mg== X-Gm-Message-State: AOAM530NIqjQ2BDQMtQdwOvSATGL1m0ArHW6HolFM3dbGdvXny0U6day jf8wtzjigAwxfQpt/hawVlIY3c5rh4Q= X-Google-Smtp-Source: ABdhPJxpZ9sl+jDHGw39Hn/2CdX8hKrMqAb+B88cWqNgvjolJt1gFgc7ilCgfJYAyBWnON27fpEMDA== X-Received: by 2002:a7b:c38c:: with SMTP id s12mr691392wmj.0.1603907833669; Wed, 28 Oct 2020 10:57:13 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id s12sm234615wmc.6.2020.10.28.10.57.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Oct 2020 10:57:12 -0700 (PDT) To: PHP Internals List References: Message-ID: Date: Wed, 28 Oct 2020 17:57:11 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] List of attributes From: rowan.collins@gmail.com (Rowan Tommins) On 28/10/2020 16:58, Nicolas Grekas wrote: > about why we'd need nested attributes, here is a discussion about > nested validation constraints: > https://github.com/symfony/symfony/issues/38503 Thanks, it's useful to see some real-world examples. As I suspected, nearly all of these explicitly take a *list* of nested attributes, not a single attribute. > While most of the constraints receive the nested constraints as simple array, |Collection| however requires a mapping (field to constraint) and is usually combined with other composite constraints, which gives us a second nesting level. There is much discussion of Collection as an edge case, but although the nested attributes are indeed inside a mapping, the *value* of that mapping is again a list of attributes. Single items are allowed, but this seems to be a special case for convenience. In the below example from https://symfony.com/doc/current/reference/constraints/Collection.html the @Assert\Email could equivalently be written as an array with one item:     /**      * @Assert\Collection(      *     fields = {      *         "personal_email" = @Assert\Email,      *         "short_bio" = {      *             @Assert\NotBlank,      *             @Assert\Length(      *                 max = 100,      *                 maxMessage = "Your short bio is too long!"      *             )      *         }      *     },      *     allowMissingFields = true      * )      */ This reinforces my earlier suggestion (https://externals.io/message/111936#112109) that #[Foo] in a nested context can simply imply an array of one attribute, rendering the above as: #[Assert\Collection(     fields: [          "personal_email" => #[Assert\Email],          "short_bio" => #[                 Assert\NotBlank,                 Assert\Length(                       max: 100,                       maxMessage: "Your short bio is too long!"                )         ]     ],     allowMissingFields: true ] Regards, -- Rowan Tommins (né Collins) [IMSoP]