Browse Source

Merge pull request #9891 from cakephp/form-subtree-split

Subtree split of Form namespace, solves #9890
Mark Story 9 years ago
parent
commit
91974ae30e
5 changed files with 102 additions and 1 deletions
  1. 1 1
      Makefile
  2. 1 0
      composer.json
  3. 22 0
      src/Form/LICENSE.txt
  4. 59 0
      src/Form/README.md
  5. 19 0
      src/Form/composer.json

+ 1 - 1
Makefile

@@ -6,7 +6,7 @@
 # Use the version number to figure out if the release
 # is a pre-release
 PRERELEASE=$(shell echo $(VERSION) | grep -E 'dev|rc|alpha|beta' --quiet && echo 'true' || echo 'false')
-COMPONENTS= filesystem log utility cache datasource core collection event validation database i18n ORM
+COMPONENTS= filesystem log utility cache datasource core collection event validation database i18n ORM form
 CURRENT_BRANCH=$(shell git branch | grep '*' | tr -d '* ')
 
 # Github settings

+ 1 - 0
composer.json

@@ -64,6 +64,7 @@
         "cakephp/database": "self.version",
         "cakephp/event": "self.version",
         "cakephp/filesystem": "self.version",
+        "cakephp/form": "self.version",
         "cakephp/i18n": "self.version",
         "cakephp/log": "self.version",
         "cakephp/orm": "self.version",

+ 22 - 0
src/Form/LICENSE.txt

@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+CakePHP(tm) : The Rapid Development PHP Framework (http://cakephp.org)
+Copyright (c) 2005-2016, Cake Software Foundation, Inc. (http://cakefoundation.org)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 59 - 0
src/Form/README.md

@@ -0,0 +1,59 @@
+[![Total Downloads](https://img.shields.io/packagist/dt/cakephp/form.svg?style=flat-square)](https://packagist.org/packages/cakephp/form)
+[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.txt)
+
+# CakePHP Form Library
+
+Form abstraction used to create forms not tied to ORM backed models,
+or to other permanent datastores. Ideal for implementing forms on top of
+API services, or contact forms.
+
+## Usage
+
+
+```php
+class ContactForm extends Form
+{
+
+    protected function _buildSchema(Schema $schema)
+    {
+        return $schema->addField('name', 'string')
+            ->addField('email', ['type' => 'string'])
+            ->addField('body', ['type' => 'text']);
+    }
+
+    protected function _buildValidator(Validator $validator)
+    {
+        return $validator->add('name', 'length', [
+                'rule' => ['minLength', 10],
+                'message' => 'A name is required'
+            ])->add('email', 'format', [
+                'rule' => 'email',
+                'message' => 'A valid email address is required',
+            ]);
+    }
+
+    protected function _execute(array $data)
+    {
+        // Send an email.
+        return true;
+    }
+}
+```
+
+In the above example we see the 3 hook methods that forms provide:
+
+- `_buildSchema()` is used to define the schema data. You can define field type, length, and precision.
+- `_buildValidator()` Gets a `Cake\Validation\Validator` instance that you can attach validators to.
+- `_execute()` lets you define the behavior you want to happen when `execute()` is called and the data is valid.
+
+You can always define additional public methods as you need as well.
+
+```php
+$contact = new ContactForm();
+$success = $contact->execute($data);
+$errors = $contact->errors();
+```
+
+## Documentation
+
+Please make sure you check the [official documentation](http://book.cakephp.org/3.0/en/core-libraries/form.html)

+ 19 - 0
src/Form/composer.json

@@ -0,0 +1,19 @@
+{
+    "name": "cakephp/form",
+    "description": "CakePHP Form library",
+    "license": "MIT",
+    "authors": [
+        {
+            "name": "CakePHP Community",
+            "homepage": "http://cakephp.org"
+        }
+    ],
+    "autoload": {
+        "psr-4": {
+            "Cake\\Form\\": "."
+        }
+    },
+    "require": {
+        "cakephp/validation": "~3.0"
+    }
+}