1 parent
3d1009bb8e
commit
080fb4f840
17 files changed
+874
-37
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
/tests export-ignore
|
||||||
|
.gitattributes export-ignore
|
||||||
|
.gitignore export-ignore
|
||||||
|
.scrutinizer.yml export-ignore
|
||||||
|
.travis.yml export-ignore
|
||||||
|
phpunit.php export-ignore
|
||||||
|
phpunit.xml export-ignore
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
/vendor
|
||||||
|
composer.phar
|
||||||
|
composer.lock
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
.idea
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
filter:
|
||||||
|
excluded_paths: [tests/*]
|
||||||
|
|
||||||
|
checks:
|
||||||
|
php:
|
||||||
|
code_rating: true
|
||||||
|
duplication: true
|
||||||
|
variable_existence: true
|
||||||
|
useless_calls: true
|
||||||
|
use_statement_alias_conflict: true
|
||||||
|
unused_variables: true
|
||||||
|
unused_properties: true
|
||||||
|
unused_parameters: true
|
||||||
|
unused_methods: true
|
||||||
|
unreachable_code: true
|
||||||
|
sql_injection_vulnerabilities: true
|
||||||
|
security_vulnerabilities: true
|
||||||
|
precedence_mistakes: true
|
||||||
|
precedence_in_conditions: true
|
||||||
|
parameter_non_unique: true
|
||||||
|
no_property_on_interface: true
|
||||||
|
no_non_implemented_abstract_methods: true
|
||||||
|
deprecated_code_usage: true
|
||||||
|
closure_use_not_conflicting: true
|
||||||
|
closure_use_modifiable: true
|
||||||
|
avoid_useless_overridden_methods: true
|
||||||
|
avoid_conflicting_incrementers: true
|
||||||
|
assignment_of_null_return: true
|
||||||
|
avoid_usage_of_logical_operators: true
|
||||||
|
ensure_lower_case_builtin_functions: true
|
||||||
|
foreach_traversable: true
|
||||||
|
function_in_camel_caps: true
|
||||||
|
instanceof_class_exists: true
|
||||||
|
lowercase_basic_constants: true
|
||||||
|
lowercase_php_keywords: true
|
||||||
|
missing_arguments: true
|
||||||
|
no_commented_out_code: true
|
||||||
|
no_duplicate_arguments: true
|
||||||
|
no_else_if_statements: true
|
||||||
|
no_space_between_concatenation_operator: true
|
||||||
|
no_space_inside_cast_operator: true
|
||||||
|
no_trailing_whitespace: true
|
||||||
|
no_underscore_prefix_in_properties: true
|
||||||
|
no_unnecessary_if: true
|
||||||
|
no_unnecessary_function_call_in_for_loop: true
|
||||||
|
non_commented_empty_catch_block: true
|
||||||
|
php5_style_constructor: true
|
||||||
|
parameters_in_camelcaps: true
|
||||||
|
prefer_while_loop_over_for_loop: true
|
||||||
|
properties_in_camelcaps: true
|
||||||
|
require_scope_for_methods: true
|
||||||
|
require_scope_for_properties: true
|
||||||
|
spacing_around_conditional_operators: true
|
||||||
|
spacing_around_non_conditional_operators: true
|
||||||
|
spacing_of_function_arguments: true
|
||||||
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
language: php
|
||||||
|
|
||||||
|
php:
|
||||||
|
- 5.4
|
||||||
|
- 5.5
|
||||||
|
- 5.6
|
||||||
|
- hhvm
|
||||||
|
|
||||||
|
sudo: false
|
||||||
|
|
||||||
|
install: travis_retry composer install --no-interaction --prefer-source
|
||||||
|
|
||||||
|
script: vendor/bin/phpunit
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
# Laravel Contribution Guide
|
||||||
|
|
||||||
|
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](http://laravel.com/docs/contributions). Please review the entire guide before sending a pull request.
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) <Adam Engebretson>
|
||||||
|
|
||||||
|
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.
|
||||||
+29
-26
@@ -1,30 +1,33 @@
|
|||||||
{
|
{
|
||||||
"name": "illuminate/html",
|
"name": "illuminate/html",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Taylor Otwell",
|
"name": "Adam Engebretson",
|
||||||
"email": "taylorotwell@gmail.com"
|
"email": "adam@laravelcollective.com"
|
||||||
}
|
|
||||||
],
|
|
||||||
"require": {
|
|
||||||
"php": ">=5.4.0",
|
|
||||||
"illuminate/http": "~5.0",
|
|
||||||
"illuminate/session": "~5.0",
|
|
||||||
"illuminate/support": "~5.0"
|
|
||||||
},
|
},
|
||||||
"autoload": {
|
{
|
||||||
"psr-4": {
|
"name": "Taylor Otwell",
|
||||||
"Illuminate\\Html\\": ""
|
"email": "taylorotwell@gmail.com"
|
||||||
},
|
}
|
||||||
"files": [
|
],
|
||||||
"helpers.php"
|
"require": {
|
||||||
]
|
"php": ">=5.4.0",
|
||||||
|
"illuminate/http": "~5.0",
|
||||||
|
"illuminate/routing": "~5.0",
|
||||||
|
"illuminate/session": "~5.0",
|
||||||
|
"illuminate/support": "~5.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"mockery/mockery": "~0.9",
|
||||||
|
"phpunit/phpunit": "~4.0"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Collective\\Html\\": "src/"
|
||||||
},
|
},
|
||||||
"extra": {
|
"files": [
|
||||||
"branch-alias": {
|
"src/helpers.php"
|
||||||
"dev-master": "5.0-dev"
|
]
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"minimum-stability": "dev"
|
|
||||||
}
|
}
|
||||||
Executable
+28
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Register The Composer Auto Loader
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Composer provides a convenient, automatically generated class loader
|
||||||
|
| for our application. We just need to utilize it! We'll require it
|
||||||
|
| into the script here so that we do not have to worry about the
|
||||||
|
| loading of any our classes "manually". Feels great to relax.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
require __DIR__.'/vendor/autoload.php';
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Set The Default Timezone
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here we will set the default timezone for PHP. PHP is notoriously mean
|
||||||
|
| if the timezone is not explicitly set. This will be used by each of
|
||||||
|
| the PHP date and date-time functions throughout the application.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
Executable
+26
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit backupGlobals="false"
|
||||||
|
backupStaticAttributes="false"
|
||||||
|
bootstrap="phpunit.php"
|
||||||
|
colors="true"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
processIsolation="false"
|
||||||
|
stopOnError="false"
|
||||||
|
stopOnFailure="false"
|
||||||
|
syntaxCheck="true"
|
||||||
|
strict="false"
|
||||||
|
verbose="true"
|
||||||
|
>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Laravel Html Test Suite">
|
||||||
|
<directory suffix="Test.php">./tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<filter>
|
||||||
|
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||||
|
<directory suffix=".php">./src</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
</phpunit>
|
||||||
@@ -0,0 +1,235 @@
|
|||||||
|
# Forms & HTML
|
||||||
|
|
||||||
|
[](https://travis-ci.org/LaravelCollective/html)
|
||||||
|
[](https://packagist.org/packages/laravelcollective/html)
|
||||||
|
[](https://packagist.org/packages/laravelcollective/html)
|
||||||
|
[](https://packagist.org/packages/laravelcollective/html)
|
||||||
|
[](https://packagist.org/packages/laravelcollective/html)
|
||||||
|
|
||||||
|
- [Installation](#installation)
|
||||||
|
- [Opening A Form](#opening-a-form)
|
||||||
|
- [CSRF Protection](#csrf-protection)
|
||||||
|
- [Form Model Binding](#form-model-binding)
|
||||||
|
- [Labels](#labels)
|
||||||
|
- [Text, Text Area, Password & Hidden Fields](#text)
|
||||||
|
- [Checkboxes and Radio Buttons](#checkboxes-and-radio-buttons)
|
||||||
|
- [File Input](#file-input)
|
||||||
|
- [Number Input](#number)
|
||||||
|
- [Drop-Down Lists](#drop-down-lists)
|
||||||
|
- [Buttons](#buttons)
|
||||||
|
- [Custom Macros](#custom-macros)
|
||||||
|
- [Generating URLs](#generating-urls)
|
||||||
|
|
||||||
|
<a name="installation"></a>
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Begin by installing this package through Composer. Edit your project's `composer.json` file to require `laravelcollective/html`.
|
||||||
|
|
||||||
|
"require": {
|
||||||
|
"laravelcollective/html": "~5.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
Next, update Composer from the Terminal:
|
||||||
|
|
||||||
|
composer update
|
||||||
|
|
||||||
|
Finally, add your new provider to the `providers` array of `config/app.php`:
|
||||||
|
|
||||||
|
```php
|
||||||
|
'providers' => [
|
||||||
|
// ...
|
||||||
|
'Collective\Html\HtmlServiceProvider',
|
||||||
|
// ...
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
|
<a name="opening-a-form"></a>
|
||||||
|
## Opening A Form
|
||||||
|
|
||||||
|
#### Opening A Form
|
||||||
|
|
||||||
|
{{ Form::open(array('url' => 'foo/bar')) }}
|
||||||
|
//
|
||||||
|
{{ Form::close() }}
|
||||||
|
|
||||||
|
By default, a `POST` method will be assumed; however, you are free to specify another method:
|
||||||
|
|
||||||
|
echo Form::open(array('url' => 'foo/bar', 'method' => 'put'))
|
||||||
|
|
||||||
|
> **Note:** Since HTML forms only support `POST` and `GET`, `PUT` and `DELETE` methods will be spoofed by automatically adding a `_method` hidden field to your form.
|
||||||
|
|
||||||
|
You may also open forms that point to named routes or controller actions:
|
||||||
|
|
||||||
|
echo Form::open(array('route' => 'route.name'))
|
||||||
|
|
||||||
|
echo Form::open(array('action' => 'Controller@method'))
|
||||||
|
|
||||||
|
You may pass in route parameters as well:
|
||||||
|
|
||||||
|
echo Form::open(array('route' => array('route.name', $user->id)))
|
||||||
|
|
||||||
|
echo Form::open(array('action' => array('Controller@method', $user->id)))
|
||||||
|
|
||||||
|
If your form is going to accept file uploads, add a `files` option to your array:
|
||||||
|
|
||||||
|
echo Form::open(array('url' => 'foo/bar', 'files' => true))
|
||||||
|
|
||||||
|
<a name="csrf-protection"></a>
|
||||||
|
## CSRF Protection
|
||||||
|
|
||||||
|
#### Adding The CSRF Token To A Form
|
||||||
|
|
||||||
|
Laravel provides an easy method of protecting your application from cross-site request forgeries. First, a random token is placed in your user's session. If you use the `Form::open` method with `POST`, `PUT` or `DELETE` the CSRF token will be added to your forms as a hidden field automatically. Alternatively, if you wish to generate the HTML for the hidden CSRF field, you may use the `token` method:
|
||||||
|
|
||||||
|
echo Form::token();
|
||||||
|
|
||||||
|
#### Attaching The CSRF Filter To A Route
|
||||||
|
|
||||||
|
Route::post('profile', array('before' => 'csrf', function()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}));
|
||||||
|
|
||||||
|
<a name="form-model-binding"></a>
|
||||||
|
## Form Model Binding
|
||||||
|
|
||||||
|
#### Opening A Model Form
|
||||||
|
|
||||||
|
Often, you will want to populate a form based on the contents of a model. To do so, use the `Form::model` method:
|
||||||
|
|
||||||
|
echo Form::model($user, array('route' => array('user.update', $user->id)))
|
||||||
|
|
||||||
|
Now, when you generate a form element, like a text input, the model's value matching the field's name will automatically be set as the field value. So, for example, for a text input named `email`, the user model's `email` attribute would be set as the value. However, there's more! If there is an item in the Session flash data matching the input name, that will take precedence over the model's value. So, the priority looks like this:
|
||||||
|
|
||||||
|
1. Session Flash Data (Old Input)
|
||||||
|
2. Explicitly Passed Value
|
||||||
|
3. Model Attribute Data
|
||||||
|
|
||||||
|
This allows you to quickly build forms that not only bind to model values, but easily re-populate if there is a validation error on the server!
|
||||||
|
|
||||||
|
> **Note:** When using `Form::model`, be sure to close your form with `Form::close`!
|
||||||
|
|
||||||
|
<a name="labels"></a>
|
||||||
|
## Labels
|
||||||
|
|
||||||
|
#### Generating A Label Element
|
||||||
|
|
||||||
|
echo Form::label('email', 'E-Mail Address');
|
||||||
|
|
||||||
|
#### Specifying Extra HTML Attributes
|
||||||
|
|
||||||
|
echo Form::label('email', 'E-Mail Address', array('class' => 'awesome'));
|
||||||
|
|
||||||
|
> **Note:** After creating a label, any form element you create with a name matching the label name will automatically receive an ID matching the label name as well.
|
||||||
|
|
||||||
|
<a name="text"></a>
|
||||||
|
## Text, Text Area, Password & Hidden Fields
|
||||||
|
|
||||||
|
#### Generating A Text Input
|
||||||
|
|
||||||
|
echo Form::text('username');
|
||||||
|
|
||||||
|
#### Specifying A Default Value
|
||||||
|
|
||||||
|
echo Form::text('email', 'example@gmail.com');
|
||||||
|
|
||||||
|
> **Note:** The *hidden* and *textarea* methods have the same signature as the *text* method.
|
||||||
|
|
||||||
|
#### Generating A Password Input
|
||||||
|
|
||||||
|
echo Form::password('password');
|
||||||
|
|
||||||
|
#### Generating Other Inputs
|
||||||
|
|
||||||
|
echo Form::email($name, $value = null, $attributes = array());
|
||||||
|
echo Form::file($name, $attributes = array());
|
||||||
|
|
||||||
|
<a name="checkboxes-and-radio-buttons"></a>
|
||||||
|
## Checkboxes and Radio Buttons
|
||||||
|
|
||||||
|
#### Generating A Checkbox Or Radio Input
|
||||||
|
|
||||||
|
echo Form::checkbox('name', 'value');
|
||||||
|
|
||||||
|
echo Form::radio('name', 'value');
|
||||||
|
|
||||||
|
#### Generating A Checkbox Or Radio Input That Is Checked
|
||||||
|
|
||||||
|
echo Form::checkbox('name', 'value', true);
|
||||||
|
|
||||||
|
echo Form::radio('name', 'value', true);
|
||||||
|
|
||||||
|
<a name="number"></a>
|
||||||
|
## Number
|
||||||
|
|
||||||
|
#### Generating A Number Input
|
||||||
|
|
||||||
|
echo Form::number('name', 'value');
|
||||||
|
|
||||||
|
<a name="file-input"></a>
|
||||||
|
## File Input
|
||||||
|
|
||||||
|
#### Generating A File Input
|
||||||
|
|
||||||
|
echo Form::file('image');
|
||||||
|
|
||||||
|
> **Note:** The form must have been opened with the `files` option set to `true`.
|
||||||
|
|
||||||
|
<a name="drop-down-lists"></a>
|
||||||
|
## Drop-Down Lists
|
||||||
|
|
||||||
|
#### Generating A Drop-Down List
|
||||||
|
|
||||||
|
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'));
|
||||||
|
|
||||||
|
#### Generating A Drop-Down List With Selected Default
|
||||||
|
|
||||||
|
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'S');
|
||||||
|
|
||||||
|
#### Generating A Grouped List
|
||||||
|
|
||||||
|
echo Form::select('animal', array(
|
||||||
|
'Cats' => array('leopard' => 'Leopard'),
|
||||||
|
'Dogs' => array('spaniel' => 'Spaniel'),
|
||||||
|
));
|
||||||
|
|
||||||
|
#### Generating A Drop-Down List With A Range
|
||||||
|
|
||||||
|
echo Form::selectRange('number', 10, 20);
|
||||||
|
|
||||||
|
#### Generating A List With Month Names
|
||||||
|
|
||||||
|
echo Form::selectMonth('month');
|
||||||
|
|
||||||
|
<a name="buttons"></a>
|
||||||
|
## Buttons
|
||||||
|
|
||||||
|
#### Generating A Submit Button
|
||||||
|
|
||||||
|
echo Form::submit('Click Me!');
|
||||||
|
|
||||||
|
> **Note:** Need to create a button element? Try the *button* method. It has the same signature as *submit*.
|
||||||
|
|
||||||
|
<a name="custom-macros"></a>
|
||||||
|
## Custom Macros
|
||||||
|
|
||||||
|
#### Registering A Form Macro
|
||||||
|
|
||||||
|
It's easy to define your own custom Form class helpers called "macros". Here's how it works. First, simply register the macro with a given name and a Closure:
|
||||||
|
|
||||||
|
Form::macro('myField', function()
|
||||||
|
{
|
||||||
|
return '<input type="awesome">';
|
||||||
|
});
|
||||||
|
|
||||||
|
Now you can call your macro using its name:
|
||||||
|
|
||||||
|
#### Calling A Custom Form Macro
|
||||||
|
|
||||||
|
echo Form::myField();
|
||||||
|
|
||||||
|
|
||||||
|
<a name="generating-urls"></a>
|
||||||
|
##Generating URLs
|
||||||
|
|
||||||
|
For more information on generating URL's, check out the documentation on [helpers](/docs/helpers#urls).
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?php namespace Illuminate\Html;
|
<?php namespace Collective\Html;
|
||||||
|
|
||||||
use Illuminate\Routing\UrlGenerator;
|
use Illuminate\Routing\UrlGenerator;
|
||||||
use Illuminate\Session\Store as Session;
|
use Illuminate\Session\Store as Session;
|
||||||
@@ -11,7 +11,7 @@ class FormBuilder {
|
|||||||
/**
|
/**
|
||||||
* The HTML builder instance.
|
* The HTML builder instance.
|
||||||
*
|
*
|
||||||
* @var \Illuminate\Html\HtmlBuilder
|
* @var \Collective\Html\HtmlBuilder
|
||||||
*/
|
*/
|
||||||
protected $html;
|
protected $html;
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ class FormBuilder {
|
|||||||
* Create a new form builder instance.
|
* Create a new form builder instance.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Routing\UrlGenerator $url
|
* @param \Illuminate\Routing\UrlGenerator $url
|
||||||
* @param \Illuminate\Html\HtmlBuilder $html
|
* @param \Collective\Html\HtmlBuilder $html
|
||||||
* @param string $csrfToken
|
* @param string $csrfToken
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php namespace Illuminate\Html;
|
<?php namespace Collective\Html;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \Illuminate\Html\FormBuilder
|
* @see \Collective\Html\FormBuilder
|
||||||
*/
|
*/
|
||||||
class FormFacade extends Facade {
|
class FormFacade extends Facade {
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?php namespace Illuminate\Html;
|
<?php namespace Collective\Html;
|
||||||
|
|
||||||
use Illuminate\Routing\UrlGenerator;
|
use Illuminate\Routing\UrlGenerator;
|
||||||
use Illuminate\Support\Traits\Macroable;
|
use Illuminate\Support\Traits\Macroable;
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php namespace Illuminate\Html;
|
<?php namespace Collective\Html;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \Illuminate\Html\HtmlBuilder
|
* @see \Collective\Html\HtmlBuilder
|
||||||
*/
|
*/
|
||||||
class HtmlFacade extends Facade {
|
class HtmlFacade extends Facade {
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?php namespace Illuminate\Html;
|
<?php namespace Collective\Html;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
@@ -22,8 +22,8 @@ class HtmlServiceProvider extends ServiceProvider {
|
|||||||
|
|
||||||
$this->registerFormBuilder();
|
$this->registerFormBuilder();
|
||||||
|
|
||||||
$this->app->alias('html', 'Illuminate\Html\HtmlBuilder');
|
$this->app->alias('html', 'Collective\Html\HtmlBuilder');
|
||||||
$this->app->alias('form', 'Illuminate\Html\FormBuilder');
|
$this->app->alias('form', 'Collective\Html\FormBuilder');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
File renamed without changes.
@@ -0,0 +1,440 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Session\Store;
|
||||||
|
use Mockery as m;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Collective\Html\FormBuilder;
|
||||||
|
use Collective\Html\HtmlBuilder;
|
||||||
|
use Illuminate\Routing\UrlGenerator;
|
||||||
|
use Illuminate\Routing\RouteCollection;
|
||||||
|
|
||||||
|
class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the test environment.
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->urlGenerator = new UrlGenerator(new RouteCollection, Request::create('/foo', 'GET'));
|
||||||
|
$this->htmlBuilder = new HtmlBuilder($this->urlGenerator);
|
||||||
|
$this->formBuilder = new FormBuilder($this->htmlBuilder, $this->urlGenerator, 'abc');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the test environment.
|
||||||
|
*/
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
m::close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testOpeningForm()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->open(['method' => 'GET']);
|
||||||
|
$form2 = $this->formBuilder->open(['method' => 'POST', 'class' => 'form', 'id' => 'id-form']);
|
||||||
|
$form3 = $this->formBuilder->open(['method' => 'GET', 'accept-charset' => 'UTF-16']);
|
||||||
|
$form4 = $this->formBuilder->open(['method' => 'GET', 'accept-charset' => 'UTF-16', 'files' => true]);
|
||||||
|
$form5 = $this->formBuilder->open(['method' => 'PUT']);
|
||||||
|
|
||||||
|
|
||||||
|
$this->assertEquals('<form method="GET" action="http://localhost/foo" accept-charset="UTF-8">', $form1);
|
||||||
|
$this->assertEquals('<form method="POST" action="http://localhost/foo" accept-charset="UTF-8" class="form" id="id-form"><input name="_token" type="hidden" value="abc">', $form2);
|
||||||
|
$this->assertEquals('<form method="GET" action="http://localhost/foo" accept-charset="UTF-16">', $form3);
|
||||||
|
$this->assertEquals('<form method="GET" action="http://localhost/foo" accept-charset="UTF-16" enctype="multipart/form-data">', $form4);
|
||||||
|
$this->assertEquals('<form method="POST" action="http://localhost/foo" accept-charset="UTF-8"><input name="_method" type="hidden" value="PUT"><input name="_token" type="hidden" value="abc">', $form5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testClosingForm()
|
||||||
|
{
|
||||||
|
$this->assertEquals('</form>', $this->formBuilder->close());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormLabel()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->label('foo', 'Foobar');
|
||||||
|
$form2 = $this->formBuilder->label('foo', 'Foobar', ['class' => 'control-label']);
|
||||||
|
|
||||||
|
$this->assertEquals('<label for="foo">Foobar</label>', $form1);
|
||||||
|
$this->assertEquals('<label for="foo" class="control-label">Foobar</label>', $form2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormInput()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->input('text', 'foo');
|
||||||
|
$form2 = $this->formBuilder->input('text', 'foo', 'foobar');
|
||||||
|
$form3 = $this->formBuilder->input('date', 'foobar', null, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="text">', $form1);
|
||||||
|
$this->assertEquals('<input name="foo" type="text" value="foobar">', $form2);
|
||||||
|
$this->assertEquals('<input class="span2" name="foobar" type="date">', $form3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testPasswordsNotFilled()
|
||||||
|
{
|
||||||
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->never();
|
||||||
|
|
||||||
|
$form1 = $this->formBuilder->password('password');
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="password" type="password" value="">', $form1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFilesNotFilled()
|
||||||
|
{
|
||||||
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->never();
|
||||||
|
|
||||||
|
$form = $this->formBuilder->file('img');
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="img" type="file">', $form);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormText()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->input('text', 'foo');
|
||||||
|
$form2 = $this->formBuilder->text('foo');
|
||||||
|
$form3 = $this->formBuilder->text('foo', 'foobar');
|
||||||
|
$form4 = $this->formBuilder->text('foo', null, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="text">', $form1);
|
||||||
|
$this->assertEquals($form1, $form2);
|
||||||
|
$this->assertEquals('<input name="foo" type="text" value="foobar">', $form3);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="text">', $form4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormTextRepopulation()
|
||||||
|
{
|
||||||
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
|
$this->setModel($model = ['relation' => ['key' => 'attribute'], 'other' => 'val']);
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->twice()->with('name_with_dots')->andReturn('some value');
|
||||||
|
$input = $this->formBuilder->text('name.with.dots', 'default value');
|
||||||
|
$this->assertEquals('<input name="name.with.dots" type="text" value="some value">', $input);
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->once()->with('text.key.sub')->andReturn(null);
|
||||||
|
$input = $this->formBuilder->text('text[key][sub]', 'default value');
|
||||||
|
$this->assertEquals('<input name="text[key][sub]" type="text" value="default value">', $input);
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->with('relation.key')->andReturn(null);
|
||||||
|
$input1 = $this->formBuilder->text('relation[key]');
|
||||||
|
|
||||||
|
$this->setModel($model, false);
|
||||||
|
$input2 = $this->formBuilder->text('relation[key]');
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="relation[key]" type="text" value="attribute">', $input1);
|
||||||
|
$this->assertEquals($input1, $input2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormPassword()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->password('foo');
|
||||||
|
$form2 = $this->formBuilder->password('foo', ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="password" value="">', $form1);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="password" value="">', $form2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormHidden()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->hidden('foo');
|
||||||
|
$form2 = $this->formBuilder->hidden('foo', 'foobar');
|
||||||
|
$form3 = $this->formBuilder->hidden('foo', null, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="hidden">', $form1);
|
||||||
|
$this->assertEquals('<input name="foo" type="hidden" value="foobar">', $form2);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="hidden">', $form3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormEmail()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->email('foo');
|
||||||
|
$form2 = $this->formBuilder->email('foo', 'foobar');
|
||||||
|
$form3 = $this->formBuilder->email('foo', null, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="email">', $form1);
|
||||||
|
$this->assertEquals('<input name="foo" type="email" value="foobar">', $form2);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="email">', $form3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormFile()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->file('foo');
|
||||||
|
$form2 = $this->formBuilder->file('foo', ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="file">', $form1);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="file">', $form2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormTextarea()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->textarea('foo');
|
||||||
|
$form2 = $this->formBuilder->textarea('foo', 'foobar');
|
||||||
|
$form3 = $this->formBuilder->textarea('foo', null, ['class' => 'span2']);
|
||||||
|
$form4 = $this->formBuilder->textarea('foo', null, ['size' => '60x15']);
|
||||||
|
|
||||||
|
$this->assertEquals('<textarea name="foo" cols="50" rows="10"></textarea>', $form1);
|
||||||
|
$this->assertEquals('<textarea name="foo" cols="50" rows="10">foobar</textarea>', $form2);
|
||||||
|
$this->assertEquals('<textarea class="span2" name="foo" cols="50" rows="10"></textarea>', $form3);
|
||||||
|
$this->assertEquals('<textarea name="foo" cols="60" rows="15"></textarea>', $form4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testSelect()
|
||||||
|
{
|
||||||
|
$select = $this->formBuilder->select(
|
||||||
|
'size',
|
||||||
|
['L' => 'Large', 'S' => 'Small']
|
||||||
|
);
|
||||||
|
$this->assertEquals($select, '<select name="size"><option value="L">Large</option><option value="S">Small</option></select>');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$select = $this->formBuilder->select(
|
||||||
|
'size',
|
||||||
|
['L' => 'Large', 'S' => 'Small'],
|
||||||
|
'L'
|
||||||
|
);
|
||||||
|
$this->assertEquals($select, '<select name="size"><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$select = $this->formBuilder->select(
|
||||||
|
'size',
|
||||||
|
['L' => 'Large', 'S' => 'Small'],
|
||||||
|
null,
|
||||||
|
['class' => 'class-name', 'id' => 'select-id']
|
||||||
|
);
|
||||||
|
$this->assertEquals($select, '<select class="class-name" id="select-id" name="size"><option value="L">Large</option><option value="S">Small</option></select>');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$this->formBuilder->label('select-name-id');
|
||||||
|
$select = $this->formBuilder->select(
|
||||||
|
'select-name-id',
|
||||||
|
[],
|
||||||
|
null,
|
||||||
|
['name' => 'select-name']
|
||||||
|
);
|
||||||
|
$this->assertEquals($select, '<select name="select-name" id="select-name-id"></select>');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormSelectRepopulation()
|
||||||
|
{
|
||||||
|
$list = ['L' => 'Large', 'M' => 'Medium', 'S' => 'Small'];
|
||||||
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
|
$this->setModel($model = ['size' => ['key' => 'S'], 'other' => 'val']);
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->twice()->with('size')->andReturn('M');
|
||||||
|
$select = $this->formBuilder->select('size', $list, 'S');
|
||||||
|
$this->assertEquals($select, '<select name="size"><option value="L">Large</option><option value="M" selected="selected">Medium</option><option value="S">Small</option></select>');
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->twice()->with('size.multi')->andReturn(['L', 'S']);
|
||||||
|
$select = $this->formBuilder->select('size[multi][]', $list, 'M', ['multiple' => 'multiple']);
|
||||||
|
$this->assertEquals($select, '<select multiple="multiple" name="size[multi][]"><option value="L" selected="selected">Large</option><option value="M">Medium</option><option value="S" selected="selected">Small</option></select>');
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->once()->with('size.key')->andReturn(null);
|
||||||
|
$select = $this->formBuilder->select('size[key]', $list);
|
||||||
|
$this->assertEquals($select, '<select name="size[key]"><option value="L">Large</option><option value="M">Medium</option><option value="S" selected="selected">Small</option></select>');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormSelectYear()
|
||||||
|
{
|
||||||
|
$select1 = $this->formBuilder->selectYear('year', 2000, 2020);
|
||||||
|
$select2 = $this->formBuilder->selectYear('year', 2000, 2020, null, ['id' => 'foo']);
|
||||||
|
$select3 = $this->formBuilder->selectYear('year', 2000, 2020, '2000');
|
||||||
|
|
||||||
|
$this->assertContains('<select name="year"><option value="2000">2000</option><option value="2001">2001</option>', $select1);
|
||||||
|
$this->assertContains('<select id="foo" name="year"><option value="2000">2000</option><option value="2001">2001</option>', $select2);
|
||||||
|
$this->assertContains('<select name="year"><option value="2000" selected="selected">2000</option><option value="2001">2001</option>', $select3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormSelectRange()
|
||||||
|
{
|
||||||
|
$range = $this->formBuilder->selectRange('dob', 1900, 2013);
|
||||||
|
|
||||||
|
$this->assertContains('<select name="dob"><option value="1900">1900</option>', $range);
|
||||||
|
$this->assertContains('<option value="2013">2013</option>', $range);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormSelectMonth()
|
||||||
|
{
|
||||||
|
$month1 = $this->formBuilder->selectMonth('month');
|
||||||
|
$month2 = $this->formBuilder->selectMonth('month', '1');
|
||||||
|
$month3 = $this->formBuilder->selectMonth('month', null, ['id' => 'foo']);
|
||||||
|
|
||||||
|
$this->assertContains('<select name="month"><option value="1">January</option><option value="2">February</option>', $month1);
|
||||||
|
$this->assertContains('<select name="month"><option value="1" selected="selected">January</option>', $month2);
|
||||||
|
$this->assertContains('<select id="foo" name="month"><option value="1">January</option>', $month3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormCheckbox()
|
||||||
|
{
|
||||||
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->withNoArgs()->andReturn([]);
|
||||||
|
$session->shouldReceive('getOldInput')->with('foo')->andReturn(null);
|
||||||
|
|
||||||
|
$form1 = $this->formBuilder->input('checkbox', 'foo');
|
||||||
|
$form2 = $this->formBuilder->checkbox('foo');
|
||||||
|
$form3 = $this->formBuilder->checkbox('foo', 'foobar', true);
|
||||||
|
$form4 = $this->formBuilder->checkbox('foo', 'foobar', false, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="checkbox">', $form1);
|
||||||
|
$this->assertEquals('<input name="foo" type="checkbox" value="1">', $form2);
|
||||||
|
$this->assertEquals('<input checked="checked" name="foo" type="checkbox" value="foobar">', $form3);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="checkbox" value="foobar">', $form4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormCheckboxRepopulation()
|
||||||
|
{
|
||||||
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
|
$session->shouldReceive('getOldInput')->withNoArgs()->andReturn([1]);
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->once()->with('check')->andReturn(null);
|
||||||
|
$check = $this->formBuilder->checkbox('check', 1, true);
|
||||||
|
$this->assertEquals('<input name="check" type="checkbox" value="1">', $check);
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->with('check.key')->andReturn('yes');
|
||||||
|
$check = $this->formBuilder->checkbox('check[key]', 'yes');
|
||||||
|
$this->assertEquals('<input checked="checked" name="check[key]" type="checkbox" value="yes">', $check);
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->with('multicheck')->andReturn([1, 3]);
|
||||||
|
$check1 = $this->formBuilder->checkbox('multicheck[]', 1);
|
||||||
|
$check2 = $this->formBuilder->checkbox('multicheck[]', 2, true);
|
||||||
|
$check3 = $this->formBuilder->checkbox('multicheck[]', 3);
|
||||||
|
|
||||||
|
$this->assertEquals('<input checked="checked" name="multicheck[]" type="checkbox" value="1">', $check1);
|
||||||
|
$this->assertEquals('<input name="multicheck[]" type="checkbox" value="2">', $check2);
|
||||||
|
$this->assertEquals('<input checked="checked" name="multicheck[]" type="checkbox" value="3">', $check3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormCheckboxWithoutSession()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->checkbox('foo');
|
||||||
|
$form2 = $this->formBuilder->checkbox('foo', 'foobar', true);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="checkbox" value="1">', $form1);
|
||||||
|
$this->assertEquals('<input checked="checked" name="foo" type="checkbox" value="foobar">', $form2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormRadio()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->input('radio', 'foo');
|
||||||
|
$form2 = $this->formBuilder->radio('foo');
|
||||||
|
$form3 = $this->formBuilder->radio('foo', 'foobar', true);
|
||||||
|
$form4 = $this->formBuilder->radio('foo', 'foobar', false, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="radio">', $form1);
|
||||||
|
$this->assertEquals('<input name="foo" type="radio" value="foo">', $form2);
|
||||||
|
$this->assertEquals('<input checked="checked" name="foo" type="radio" value="foobar">', $form3);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="radio" value="foobar">', $form4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormRadioRepopulation()
|
||||||
|
{
|
||||||
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
|
|
||||||
|
$session->shouldReceive('getOldInput')->with('radio')->andReturn(1);
|
||||||
|
|
||||||
|
$radio1 = $this->formBuilder->radio('radio', 1);
|
||||||
|
$radio2 = $this->formBuilder->radio('radio', 2, true);
|
||||||
|
|
||||||
|
$this->assertEquals('<input checked="checked" name="radio" type="radio" value="1">', $radio1);
|
||||||
|
$this->assertEquals('<input name="radio" type="radio" value="2">', $radio2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormSubmit()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->submit('foo');
|
||||||
|
$form2 = $this->formBuilder->submit('foo', ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input type="submit" value="foo">', $form1);
|
||||||
|
$this->assertEquals('<input class="span2" type="submit" value="foo">', $form2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormButton()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->button('foo');
|
||||||
|
$form2 = $this->formBuilder->button('foo', ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<button type="button">foo</button>', $form1);
|
||||||
|
$this->assertEquals('<button class="span2" type="button">foo</button>', $form2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testResetInput()
|
||||||
|
{
|
||||||
|
$resetInput = $this->formBuilder->reset('foo');
|
||||||
|
$this->assertEquals('<input type="reset" value="foo">', $resetInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testImageInput()
|
||||||
|
{
|
||||||
|
$url = 'http://laravel.com/';
|
||||||
|
$image = $this->formBuilder->image($url);
|
||||||
|
|
||||||
|
$this->assertEquals('<input src="'. $url .'" type="image">', $image);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setModel(array $data, $object = true)
|
||||||
|
{
|
||||||
|
if ($object) $data = new FormBuilderModelStub($data);
|
||||||
|
|
||||||
|
$this->formBuilder->model($data, ['method' => 'GET']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FormBuilderModelStub {
|
||||||
|
|
||||||
|
protected $data;
|
||||||
|
|
||||||
|
public function __construct(array $data = [])
|
||||||
|
{
|
||||||
|
foreach ($data as $key => $val)
|
||||||
|
{
|
||||||
|
if (is_array($val)) $val = new self($val);
|
||||||
|
|
||||||
|
$this->data[$key] = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function __get($key)
|
||||||
|
{
|
||||||
|
return $this->data[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function __isset($key)
|
||||||
|
{
|
||||||
|
return isset($this->data[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user