|
|
@@ -140,9 +140,9 @@ class Form implements EventListenerInterface, EventDispatcherInterface, Validato
|
|
|
/**
|
|
|
* Set the schema for this form.
|
|
|
*
|
|
|
- * @since 4.1.0
|
|
|
* @param \Cake\Form\Schema $schema The schema to set
|
|
|
* @return $this
|
|
|
+ * @since 4.1.0
|
|
|
*/
|
|
|
public function setSchema(Schema $schema)
|
|
|
{
|
|
|
@@ -158,8 +158,8 @@ class Form implements EventListenerInterface, EventDispatcherInterface, Validato
|
|
|
* is first built. This hook method lets you configure the
|
|
|
* schema or load a pre-defined one.
|
|
|
*
|
|
|
- * @since 4.1.0
|
|
|
* @return \Cake\Form\Schema the schema instance.
|
|
|
+ * @since 4.1.0
|
|
|
*/
|
|
|
public function getSchema(): Schema
|
|
|
{
|
|
|
@@ -177,9 +177,9 @@ class Form implements EventListenerInterface, EventDispatcherInterface, Validato
|
|
|
* is first built. This hook method lets you configure the
|
|
|
* schema or load a pre-defined one.
|
|
|
*
|
|
|
- * @deprecated 4.1.0 Use {@link setSchema()}/{@link getSchema()} instead.
|
|
|
* @param \Cake\Form\Schema|null $schema The schema to set, or null.
|
|
|
* @return \Cake\Form\Schema the schema instance.
|
|
|
+ * @deprecated 4.1.0 Use {@link setSchema()}/{@link getSchema()} instead.
|
|
|
*/
|
|
|
public function schema(?Schema $schema = null): Schema
|
|
|
{
|
|
|
@@ -212,6 +212,7 @@ class Form implements EventListenerInterface, EventDispatcherInterface, Validato
|
|
|
* @param array $data The data to check.
|
|
|
* @param array $options The validate options
|
|
|
* @return bool Whether or not the data is valid.
|
|
|
+ * @throws \RuntimeException If validator is invalid.
|
|
|
*/
|
|
|
public function validate(array $data, array $options = []): bool
|
|
|
{
|
|
|
@@ -229,6 +230,12 @@ class Form implements EventListenerInterface, EventDispatcherInterface, Validato
|
|
|
$validator = $options['validate'];
|
|
|
}
|
|
|
|
|
|
+ if ($validator === null) {
|
|
|
+ throw new RuntimeException(
|
|
|
+ sprintf('validate must be a boolean, a string or an object. Got %s.', getTypeName($options['validate']))
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
$this->_errors = $validator->validate($data);
|
|
|
|
|
|
return count($this->_errors) === 0;
|