@@ -8,141 +8,141 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | interface FrameworkInterface |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Filter buttons classes |
|
| 13 | - * |
|
| 14 | - * @param array $classes An array of classes |
|
| 15 | - * |
|
| 16 | - * @return array A filtered array |
|
| 17 | - */ |
|
| 18 | - public function filterButtonClasses($classes); |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Filter field classes |
|
| 22 | - * |
|
| 23 | - * @param array $classes An array of classes |
|
| 24 | - * |
|
| 25 | - * @return array A filtered array |
|
| 26 | - */ |
|
| 27 | - public function filterFieldClasses($classes); |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Add classes to a field |
|
| 31 | - * |
|
| 32 | - * @param Field $field |
|
| 33 | - * @param array $classes The possible classes to add |
|
| 34 | - * |
|
| 35 | - * @return Field |
|
| 36 | - */ |
|
| 37 | - public function getFieldClasses(Field $field, $classes); |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Add group classes |
|
| 41 | - * |
|
| 42 | - * @return string A list of group classes |
|
| 43 | - */ |
|
| 44 | - public function getGroupClasses(); |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Add label classes |
|
| 48 | - * |
|
| 49 | - * @return array An array of attributes with the label class |
|
| 50 | - */ |
|
| 51 | - public function getLabelClasses(); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Add uneditable field classes |
|
| 55 | - * |
|
| 56 | - * @return array An array of attributes with the uneditable class |
|
| 57 | - */ |
|
| 58 | - public function getUneditableClasses(); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Add plain text field classes |
|
| 62 | - * |
|
| 63 | - * @return array An array of attributes with the plain text class |
|
| 64 | - */ |
|
| 65 | - public function getPlainTextClasses(); |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Add form class |
|
| 69 | - * |
|
| 70 | - * @param string $type The type of form to add |
|
| 71 | - * |
|
| 72 | - * @return array |
|
| 73 | - */ |
|
| 74 | - public function getFormClasses($type); |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Add actions block class |
|
| 78 | - * |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - public function getActionClasses(); |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Render an help text |
|
| 85 | - * |
|
| 86 | - * @param string $text |
|
| 87 | - * @param array $attributes |
|
| 88 | - * |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function createHelp($text, $attributes = array()); |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Render a disabled field |
|
| 95 | - * |
|
| 96 | - * @param Field $field |
|
| 97 | - * |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 100 | - public function createDisabledField(Field $field); |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Render a plain text field |
|
| 104 | - * |
|
| 105 | - * @param Field $field |
|
| 106 | - * |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 109 | - public function createPlainTextField(Field $field); |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Render an icon |
|
| 113 | - * |
|
| 114 | - * @param array $attributes Its attributes |
|
| 115 | - * |
|
| 116 | - * @return string |
|
| 117 | - */ |
|
| 118 | - public function createIcon($iconType, $attributes = array()); |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Wrap an item to be prepended or appended to the current field |
|
| 122 | - * |
|
| 123 | - * @param string $item |
|
| 124 | - * |
|
| 125 | - * @return string A wrapped item |
|
| 126 | - */ |
|
| 127 | - public function placeAround($item); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Wrap a field with prepended and appended items |
|
| 131 | - * |
|
| 132 | - * @param Field $field |
|
| 133 | - * @param array $prepend |
|
| 134 | - * @param array $append |
|
| 135 | - * |
|
| 136 | - * @return string A field concatented with prepended and/or appended items |
|
| 137 | - */ |
|
| 138 | - public function prependAppend($field, $prepend, $append); |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Wrap a field with potential additional tags |
|
| 142 | - * |
|
| 143 | - * @param Field $field |
|
| 144 | - * |
|
| 145 | - * @return string A wrapped field |
|
| 146 | - */ |
|
| 147 | - public function wrapField($field); |
|
| 11 | + /** |
|
| 12 | + * Filter buttons classes |
|
| 13 | + * |
|
| 14 | + * @param array $classes An array of classes |
|
| 15 | + * |
|
| 16 | + * @return array A filtered array |
|
| 17 | + */ |
|
| 18 | + public function filterButtonClasses($classes); |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Filter field classes |
|
| 22 | + * |
|
| 23 | + * @param array $classes An array of classes |
|
| 24 | + * |
|
| 25 | + * @return array A filtered array |
|
| 26 | + */ |
|
| 27 | + public function filterFieldClasses($classes); |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Add classes to a field |
|
| 31 | + * |
|
| 32 | + * @param Field $field |
|
| 33 | + * @param array $classes The possible classes to add |
|
| 34 | + * |
|
| 35 | + * @return Field |
|
| 36 | + */ |
|
| 37 | + public function getFieldClasses(Field $field, $classes); |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Add group classes |
|
| 41 | + * |
|
| 42 | + * @return string A list of group classes |
|
| 43 | + */ |
|
| 44 | + public function getGroupClasses(); |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Add label classes |
|
| 48 | + * |
|
| 49 | + * @return array An array of attributes with the label class |
|
| 50 | + */ |
|
| 51 | + public function getLabelClasses(); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Add uneditable field classes |
|
| 55 | + * |
|
| 56 | + * @return array An array of attributes with the uneditable class |
|
| 57 | + */ |
|
| 58 | + public function getUneditableClasses(); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Add plain text field classes |
|
| 62 | + * |
|
| 63 | + * @return array An array of attributes with the plain text class |
|
| 64 | + */ |
|
| 65 | + public function getPlainTextClasses(); |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Add form class |
|
| 69 | + * |
|
| 70 | + * @param string $type The type of form to add |
|
| 71 | + * |
|
| 72 | + * @return array |
|
| 73 | + */ |
|
| 74 | + public function getFormClasses($type); |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Add actions block class |
|
| 78 | + * |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + public function getActionClasses(); |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Render an help text |
|
| 85 | + * |
|
| 86 | + * @param string $text |
|
| 87 | + * @param array $attributes |
|
| 88 | + * |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function createHelp($text, $attributes = array()); |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Render a disabled field |
|
| 95 | + * |
|
| 96 | + * @param Field $field |
|
| 97 | + * |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | + public function createDisabledField(Field $field); |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Render a plain text field |
|
| 104 | + * |
|
| 105 | + * @param Field $field |
|
| 106 | + * |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | + public function createPlainTextField(Field $field); |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Render an icon |
|
| 113 | + * |
|
| 114 | + * @param array $attributes Its attributes |
|
| 115 | + * |
|
| 116 | + * @return string |
|
| 117 | + */ |
|
| 118 | + public function createIcon($iconType, $attributes = array()); |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Wrap an item to be prepended or appended to the current field |
|
| 122 | + * |
|
| 123 | + * @param string $item |
|
| 124 | + * |
|
| 125 | + * @return string A wrapped item |
|
| 126 | + */ |
|
| 127 | + public function placeAround($item); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Wrap a field with prepended and appended items |
|
| 131 | + * |
|
| 132 | + * @param Field $field |
|
| 133 | + * @param array $prepend |
|
| 134 | + * @param array $append |
|
| 135 | + * |
|
| 136 | + * @return string A field concatented with prepended and/or appended items |
|
| 137 | + */ |
|
| 138 | + public function prependAppend($field, $prepend, $append); |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Wrap a field with potential additional tags |
|
| 142 | + * |
|
| 143 | + * @param Field $field |
|
| 144 | + * |
|
| 145 | + * @return string A wrapped field |
|
| 146 | + */ |
|
| 147 | + public function wrapField($field); |
|
| 148 | 148 | } |
@@ -6,10 +6,10 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | interface FieldInterface |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Renders the field |
|
| 11 | - * |
|
| 12 | - * @return string |
|
| 13 | - */ |
|
| 14 | - public function render(); |
|
| 9 | + /** |
|
| 10 | + * Renders the field |
|
| 11 | + * |
|
| 12 | + * @return string |
|
| 13 | + */ |
|
| 14 | + public function render(); |
|
| 15 | 15 | } |
@@ -11,171 +11,171 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Populator extends Collection |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Create a new collection. |
|
| 16 | - * |
|
| 17 | - * @param array|Model $items |
|
| 18 | - * |
|
| 19 | - * @return void |
|
| 20 | - */ |
|
| 21 | - public function __construct($items = array()) |
|
| 22 | - { |
|
| 23 | - $this->items = $items; |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - //////////////////////////////////////////////////////////////////// |
|
| 27 | - ///////////////////////// INDIVIDUAL VALUES //////////////////////// |
|
| 28 | - //////////////////////////////////////////////////////////////////// |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Get the value of a field |
|
| 32 | - * |
|
| 33 | - * @param string $field The field's name |
|
| 34 | - * |
|
| 35 | - * @return mixed |
|
| 36 | - */ |
|
| 37 | - public function get($field, $fallback = null) |
|
| 38 | - { |
|
| 39 | - // Anonymous fields should not return any value |
|
| 40 | - if ($field == null) { |
|
| 41 | - return null; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - // Plain array |
|
| 45 | - if (is_array($this->items) and !str_contains($field, '[')) { |
|
| 46 | - return parent::get($field, $fallback); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - // Transform the name into an array |
|
| 50 | - $value = $this->items; |
|
| 51 | - $field = $this->parseFieldAsArray($field); |
|
| 52 | - |
|
| 53 | - // Dive into the model |
|
| 54 | - foreach ($field as $relationship) { |
|
| 55 | - |
|
| 56 | - // Get attribute from model |
|
| 57 | - if (!is_array($value)) { |
|
| 58 | - $value = $this->getAttributeFromModel($value, $relationship, $fallback); |
|
| 59 | - |
|
| 60 | - continue; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // Get attribute from model |
|
| 64 | - if (array_key_exists($relationship, $value)) { |
|
| 65 | - $value = $value[$relationship]; |
|
| 66 | - } else { |
|
| 67 | - // Check array for submodels that may contain the relationship |
|
| 68 | - $inSubmodel = false; |
|
| 69 | - |
|
| 70 | - foreach ($value as $key => $submodel) { |
|
| 71 | - $value[$key] = $this->getAttributeFromModel($submodel, $relationship, $fallback); |
|
| 72 | - |
|
| 73 | - if ($value[$key] !== $fallback) { |
|
| 74 | - $inSubmodel = true; |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // If no submodels contained the relationship, return the fallback, not an array of fallbacks |
|
| 79 | - if (!$inSubmodel) { |
|
| 80 | - $value = $fallback; |
|
| 81 | - break; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - return $value; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - //////////////////////////////////////////////////////////////////// |
|
| 90 | - ///////////////////////////// SWAPPERS ///////////////////////////// |
|
| 91 | - //////////////////////////////////////////////////////////////////// |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Replace the items |
|
| 95 | - * |
|
| 96 | - * @param mixed $items |
|
| 97 | - * |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public function replace($items) |
|
| 101 | - { |
|
| 102 | - $this->items = $items; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Reset the current values array |
|
| 107 | - * |
|
| 108 | - * @return void |
|
| 109 | - */ |
|
| 110 | - public function reset() |
|
| 111 | - { |
|
| 112 | - $this->items = array(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - //////////////////////////////////////////////////////////////////// |
|
| 116 | - ////////////////////////////// HELPERS ///////////////////////////// |
|
| 117 | - //////////////////////////////////////////////////////////////////// |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Parses the name of a field to a tree of fields |
|
| 121 | - * |
|
| 122 | - * @param string $field The field's name |
|
| 123 | - * |
|
| 124 | - * @return array A tree of field |
|
| 125 | - */ |
|
| 126 | - protected function parseFieldAsArray($field) |
|
| 127 | - { |
|
| 128 | - if (Str::contains($field, '[]')) { |
|
| 129 | - return (array) $field; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Transform array notation to dot notation |
|
| 133 | - if (Str::contains($field, '[')) { |
|
| 134 | - $field = preg_replace("/[\[\]]/", '.', $field); |
|
| 135 | - $field = str_replace('..', '.', $field); |
|
| 136 | - $field = trim($field, '.'); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - // Parse dot notation |
|
| 140 | - if (Str::contains($field, '.')) { |
|
| 141 | - $field = explode('.', $field); |
|
| 142 | - } else { |
|
| 143 | - $field = (array) $field; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $field; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Get an attribute from a model |
|
| 151 | - * |
|
| 152 | - * @param object $model The model |
|
| 153 | - * @param string $attribute The attribute's name |
|
| 154 | - * @param string $fallback Fallback value |
|
| 155 | - * |
|
| 156 | - * @return mixed |
|
| 157 | - */ |
|
| 158 | - public function getAttributeFromModel($model, $attribute, $fallback) |
|
| 159 | - { |
|
| 160 | - if ($model instanceof Model) { |
|
| 161 | - // Return fallback if attribute is null |
|
| 162 | - $value = $model->getAttribute($attribute); |
|
| 163 | - return is_null($value) ? $fallback : $value; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if ($model instanceof Collection) { |
|
| 167 | - return $model->get($attribute, $fallback); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if (is_object($model) && method_exists($model, 'toArray')) { |
|
| 171 | - $model = $model->toArray(); |
|
| 172 | - } else { |
|
| 173 | - $model = (array) $model; |
|
| 174 | - } |
|
| 175 | - if (array_key_exists($attribute, $model)) { |
|
| 176 | - return $model[$attribute]; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return $fallback; |
|
| 180 | - } |
|
| 14 | + /** |
|
| 15 | + * Create a new collection. |
|
| 16 | + * |
|
| 17 | + * @param array|Model $items |
|
| 18 | + * |
|
| 19 | + * @return void |
|
| 20 | + */ |
|
| 21 | + public function __construct($items = array()) |
|
| 22 | + { |
|
| 23 | + $this->items = $items; |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + //////////////////////////////////////////////////////////////////// |
|
| 27 | + ///////////////////////// INDIVIDUAL VALUES //////////////////////// |
|
| 28 | + //////////////////////////////////////////////////////////////////// |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Get the value of a field |
|
| 32 | + * |
|
| 33 | + * @param string $field The field's name |
|
| 34 | + * |
|
| 35 | + * @return mixed |
|
| 36 | + */ |
|
| 37 | + public function get($field, $fallback = null) |
|
| 38 | + { |
|
| 39 | + // Anonymous fields should not return any value |
|
| 40 | + if ($field == null) { |
|
| 41 | + return null; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + // Plain array |
|
| 45 | + if (is_array($this->items) and !str_contains($field, '[')) { |
|
| 46 | + return parent::get($field, $fallback); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + // Transform the name into an array |
|
| 50 | + $value = $this->items; |
|
| 51 | + $field = $this->parseFieldAsArray($field); |
|
| 52 | + |
|
| 53 | + // Dive into the model |
|
| 54 | + foreach ($field as $relationship) { |
|
| 55 | + |
|
| 56 | + // Get attribute from model |
|
| 57 | + if (!is_array($value)) { |
|
| 58 | + $value = $this->getAttributeFromModel($value, $relationship, $fallback); |
|
| 59 | + |
|
| 60 | + continue; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // Get attribute from model |
|
| 64 | + if (array_key_exists($relationship, $value)) { |
|
| 65 | + $value = $value[$relationship]; |
|
| 66 | + } else { |
|
| 67 | + // Check array for submodels that may contain the relationship |
|
| 68 | + $inSubmodel = false; |
|
| 69 | + |
|
| 70 | + foreach ($value as $key => $submodel) { |
|
| 71 | + $value[$key] = $this->getAttributeFromModel($submodel, $relationship, $fallback); |
|
| 72 | + |
|
| 73 | + if ($value[$key] !== $fallback) { |
|
| 74 | + $inSubmodel = true; |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // If no submodels contained the relationship, return the fallback, not an array of fallbacks |
|
| 79 | + if (!$inSubmodel) { |
|
| 80 | + $value = $fallback; |
|
| 81 | + break; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return $value; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + //////////////////////////////////////////////////////////////////// |
|
| 90 | + ///////////////////////////// SWAPPERS ///////////////////////////// |
|
| 91 | + //////////////////////////////////////////////////////////////////// |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Replace the items |
|
| 95 | + * |
|
| 96 | + * @param mixed $items |
|
| 97 | + * |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public function replace($items) |
|
| 101 | + { |
|
| 102 | + $this->items = $items; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Reset the current values array |
|
| 107 | + * |
|
| 108 | + * @return void |
|
| 109 | + */ |
|
| 110 | + public function reset() |
|
| 111 | + { |
|
| 112 | + $this->items = array(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + //////////////////////////////////////////////////////////////////// |
|
| 116 | + ////////////////////////////// HELPERS ///////////////////////////// |
|
| 117 | + //////////////////////////////////////////////////////////////////// |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Parses the name of a field to a tree of fields |
|
| 121 | + * |
|
| 122 | + * @param string $field The field's name |
|
| 123 | + * |
|
| 124 | + * @return array A tree of field |
|
| 125 | + */ |
|
| 126 | + protected function parseFieldAsArray($field) |
|
| 127 | + { |
|
| 128 | + if (Str::contains($field, '[]')) { |
|
| 129 | + return (array) $field; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Transform array notation to dot notation |
|
| 133 | + if (Str::contains($field, '[')) { |
|
| 134 | + $field = preg_replace("/[\[\]]/", '.', $field); |
|
| 135 | + $field = str_replace('..', '.', $field); |
|
| 136 | + $field = trim($field, '.'); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + // Parse dot notation |
|
| 140 | + if (Str::contains($field, '.')) { |
|
| 141 | + $field = explode('.', $field); |
|
| 142 | + } else { |
|
| 143 | + $field = (array) $field; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $field; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Get an attribute from a model |
|
| 151 | + * |
|
| 152 | + * @param object $model The model |
|
| 153 | + * @param string $attribute The attribute's name |
|
| 154 | + * @param string $fallback Fallback value |
|
| 155 | + * |
|
| 156 | + * @return mixed |
|
| 157 | + */ |
|
| 158 | + public function getAttributeFromModel($model, $attribute, $fallback) |
|
| 159 | + { |
|
| 160 | + if ($model instanceof Model) { |
|
| 161 | + // Return fallback if attribute is null |
|
| 162 | + $value = $model->getAttribute($attribute); |
|
| 163 | + return is_null($value) ? $fallback : $value; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if ($model instanceof Collection) { |
|
| 167 | + return $model->get($attribute, $fallback); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + if (is_object($model) && method_exists($model, 'toArray')) { |
|
| 171 | + $model = $model->toArray(); |
|
| 172 | + } else { |
|
| 173 | + $model = (array) $model; |
|
| 174 | + } |
|
| 175 | + if (array_key_exists($attribute, $model)) { |
|
| 176 | + return $model[$attribute]; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return $fallback; |
|
| 180 | + } |
|
| 181 | 181 | } |
@@ -7,128 +7,128 @@ |
||
| 7 | 7 | |
| 8 | 8 | class File |
| 9 | 9 | { |
| 10 | - private static $mimes = array( |
|
| 11 | - 'ai' => 'application/postscript', |
|
| 12 | - 'aif' => 'audio/x-aiff', |
|
| 13 | - 'aifc' => 'audio/x-aiff', |
|
| 14 | - 'aiff' => 'audio/x-aiff', |
|
| 15 | - 'avi' => 'video/x-msvideo', |
|
| 16 | - 'bin' => 'application/macbinary', |
|
| 17 | - 'bmp' => 'image/bmp', |
|
| 18 | - 'class' => 'application/octet-stream', |
|
| 19 | - 'cpt' => 'application/mac-compactpro', |
|
| 20 | - 'css' => 'text/css', |
|
| 21 | - 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream'), |
|
| 22 | - 'dcr' => 'application/x-director', |
|
| 23 | - 'dir' => 'application/x-director', |
|
| 24 | - 'dll' => 'application/octet-stream', |
|
| 25 | - 'dms' => 'application/octet-stream', |
|
| 26 | - 'doc' => 'application/msword', |
|
| 27 | - 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
|
| 28 | - 'dvi' => 'application/x-dvi', |
|
| 29 | - 'dxr' => 'application/x-director', |
|
| 30 | - 'eml' => 'message/rfc822', |
|
| 31 | - 'eps' => 'application/postscript', |
|
| 32 | - 'exe' => array('application/octet-stream', 'application/x-msdownload'), |
|
| 33 | - 'gif' => 'image/gif', |
|
| 34 | - 'gtar' => 'application/x-gtar', |
|
| 35 | - 'gz' => 'application/x-gzip', |
|
| 36 | - 'hqx' => 'application/mac-binhex40', |
|
| 37 | - 'htm' => 'text/html', |
|
| 38 | - 'html' => 'text/html', |
|
| 39 | - 'jpe' => array('image/jpeg', 'image/pjpeg'), |
|
| 40 | - 'jpeg' => array('image/jpeg', 'image/pjpeg'), |
|
| 41 | - 'jpg' => array('image/jpeg', 'image/pjpeg'), |
|
| 42 | - 'js' => 'application/x-javascript', |
|
| 43 | - 'json' => array('application/json', 'text/json'), |
|
| 44 | - 'lha' => 'application/octet-stream', |
|
| 45 | - 'log' => array('text/plain', 'text/x-log'), |
|
| 46 | - 'lzh' => 'application/octet-stream', |
|
| 47 | - 'mid' => 'audio/midi', |
|
| 48 | - 'midi' => 'audio/midi', |
|
| 49 | - 'mif' => 'application/vnd.mif', |
|
| 50 | - 'mov' => 'video/quicktime', |
|
| 51 | - 'movie' => 'video/x-sgi-movie', |
|
| 52 | - 'mp2' => 'audio/mpeg', |
|
| 53 | - 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'), |
|
| 54 | - 'mpe' => 'video/mpeg', |
|
| 55 | - 'mpeg' => 'video/mpeg', |
|
| 56 | - 'mpg' => 'video/mpeg', |
|
| 57 | - 'mpga' => 'audio/mpeg', |
|
| 58 | - 'oda' => 'application/oda', |
|
| 59 | - 'odp' => 'application/vnd.oasis.opendocument.presentation', |
|
| 60 | - 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
|
| 61 | - 'odt' => 'application/vnd.oasis.opendocument.text', |
|
| 62 | - 'pdf' => array('application/pdf', 'application/x-download'), |
|
| 63 | - 'php' => array('application/x-httpd-php', 'text/x-php'), |
|
| 64 | - 'php3' => 'application/x-httpd-php', |
|
| 65 | - 'php4' => 'application/x-httpd-php', |
|
| 66 | - 'phps' => 'application/x-httpd-php-source', |
|
| 67 | - 'phtml' => 'application/x-httpd-php', |
|
| 68 | - 'png' => 'image/png', |
|
| 69 | - 'pps' => array('application/mspowerpoint', 'application/vnd.ms-powerpoint'), |
|
| 70 | - 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
|
| 71 | - 'ppt' => array('application/vnd.ms-powerpoint', 'application/powerpoint'), |
|
| 72 | - 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
|
| 73 | - 'ps' => 'application/postscript', |
|
| 74 | - 'psd' => 'application/x-photoshop', |
|
| 75 | - 'qt' => 'video/quicktime', |
|
| 76 | - 'ra' => 'audio/x-realaudio', |
|
| 77 | - 'ram' => 'audio/x-pn-realaudio', |
|
| 78 | - 'rm' => 'audio/x-pn-realaudio', |
|
| 79 | - 'rpm' => 'audio/x-pn-realaudio-plugin', |
|
| 80 | - 'rtf' => array('application/rtf', 'text/rtf'), |
|
| 81 | - 'rtx' => 'text/richtext', |
|
| 82 | - 'rv' => 'video/vnd.rn-realvideo', |
|
| 83 | - 'sea' => 'application/octet-stream', |
|
| 84 | - 'shtml' => 'text/html', |
|
| 85 | - 'sit' => 'application/x-stuffit', |
|
| 86 | - 'smi' => 'application/smil', |
|
| 87 | - 'smil' => 'application/smil', |
|
| 88 | - 'so' => 'application/octet-stream', |
|
| 89 | - 'swf' => 'application/x-shockwave-flash', |
|
| 90 | - 'tar' => 'application/x-tar', |
|
| 91 | - 'text' => 'text/plain', |
|
| 92 | - 'tgz' => array('application/x-tar', 'application/x-gzip-compressed'), |
|
| 93 | - 'tif' => 'image/tiff', |
|
| 94 | - 'tiff' => 'image/tiff', |
|
| 95 | - 'txt' => 'text/plain', |
|
| 96 | - 'wav' => 'audio/x-wav', |
|
| 97 | - 'wbxml' => 'application/wbxml', |
|
| 98 | - 'wmlc' => 'application/wmlc', |
|
| 99 | - 'word' => array('application/msword', 'application/octet-stream'), |
|
| 100 | - 'xht' => 'application/xhtml+xml', |
|
| 101 | - 'xhtml' => 'application/xhtml+xml', |
|
| 102 | - 'xl' => 'application/excel', |
|
| 103 | - 'xls' => array('application/vnd.ms-excel', 'application/excel', 'application/msexcel'), |
|
| 104 | - 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
|
| 105 | - 'xml' => 'text/xml', |
|
| 106 | - 'xsl' => 'text/xml', |
|
| 107 | - 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'), |
|
| 108 | - ); |
|
| 10 | + private static $mimes = array( |
|
| 11 | + 'ai' => 'application/postscript', |
|
| 12 | + 'aif' => 'audio/x-aiff', |
|
| 13 | + 'aifc' => 'audio/x-aiff', |
|
| 14 | + 'aiff' => 'audio/x-aiff', |
|
| 15 | + 'avi' => 'video/x-msvideo', |
|
| 16 | + 'bin' => 'application/macbinary', |
|
| 17 | + 'bmp' => 'image/bmp', |
|
| 18 | + 'class' => 'application/octet-stream', |
|
| 19 | + 'cpt' => 'application/mac-compactpro', |
|
| 20 | + 'css' => 'text/css', |
|
| 21 | + 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream'), |
|
| 22 | + 'dcr' => 'application/x-director', |
|
| 23 | + 'dir' => 'application/x-director', |
|
| 24 | + 'dll' => 'application/octet-stream', |
|
| 25 | + 'dms' => 'application/octet-stream', |
|
| 26 | + 'doc' => 'application/msword', |
|
| 27 | + 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
|
| 28 | + 'dvi' => 'application/x-dvi', |
|
| 29 | + 'dxr' => 'application/x-director', |
|
| 30 | + 'eml' => 'message/rfc822', |
|
| 31 | + 'eps' => 'application/postscript', |
|
| 32 | + 'exe' => array('application/octet-stream', 'application/x-msdownload'), |
|
| 33 | + 'gif' => 'image/gif', |
|
| 34 | + 'gtar' => 'application/x-gtar', |
|
| 35 | + 'gz' => 'application/x-gzip', |
|
| 36 | + 'hqx' => 'application/mac-binhex40', |
|
| 37 | + 'htm' => 'text/html', |
|
| 38 | + 'html' => 'text/html', |
|
| 39 | + 'jpe' => array('image/jpeg', 'image/pjpeg'), |
|
| 40 | + 'jpeg' => array('image/jpeg', 'image/pjpeg'), |
|
| 41 | + 'jpg' => array('image/jpeg', 'image/pjpeg'), |
|
| 42 | + 'js' => 'application/x-javascript', |
|
| 43 | + 'json' => array('application/json', 'text/json'), |
|
| 44 | + 'lha' => 'application/octet-stream', |
|
| 45 | + 'log' => array('text/plain', 'text/x-log'), |
|
| 46 | + 'lzh' => 'application/octet-stream', |
|
| 47 | + 'mid' => 'audio/midi', |
|
| 48 | + 'midi' => 'audio/midi', |
|
| 49 | + 'mif' => 'application/vnd.mif', |
|
| 50 | + 'mov' => 'video/quicktime', |
|
| 51 | + 'movie' => 'video/x-sgi-movie', |
|
| 52 | + 'mp2' => 'audio/mpeg', |
|
| 53 | + 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'), |
|
| 54 | + 'mpe' => 'video/mpeg', |
|
| 55 | + 'mpeg' => 'video/mpeg', |
|
| 56 | + 'mpg' => 'video/mpeg', |
|
| 57 | + 'mpga' => 'audio/mpeg', |
|
| 58 | + 'oda' => 'application/oda', |
|
| 59 | + 'odp' => 'application/vnd.oasis.opendocument.presentation', |
|
| 60 | + 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
|
| 61 | + 'odt' => 'application/vnd.oasis.opendocument.text', |
|
| 62 | + 'pdf' => array('application/pdf', 'application/x-download'), |
|
| 63 | + 'php' => array('application/x-httpd-php', 'text/x-php'), |
|
| 64 | + 'php3' => 'application/x-httpd-php', |
|
| 65 | + 'php4' => 'application/x-httpd-php', |
|
| 66 | + 'phps' => 'application/x-httpd-php-source', |
|
| 67 | + 'phtml' => 'application/x-httpd-php', |
|
| 68 | + 'png' => 'image/png', |
|
| 69 | + 'pps' => array('application/mspowerpoint', 'application/vnd.ms-powerpoint'), |
|
| 70 | + 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
|
| 71 | + 'ppt' => array('application/vnd.ms-powerpoint', 'application/powerpoint'), |
|
| 72 | + 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
|
| 73 | + 'ps' => 'application/postscript', |
|
| 74 | + 'psd' => 'application/x-photoshop', |
|
| 75 | + 'qt' => 'video/quicktime', |
|
| 76 | + 'ra' => 'audio/x-realaudio', |
|
| 77 | + 'ram' => 'audio/x-pn-realaudio', |
|
| 78 | + 'rm' => 'audio/x-pn-realaudio', |
|
| 79 | + 'rpm' => 'audio/x-pn-realaudio-plugin', |
|
| 80 | + 'rtf' => array('application/rtf', 'text/rtf'), |
|
| 81 | + 'rtx' => 'text/richtext', |
|
| 82 | + 'rv' => 'video/vnd.rn-realvideo', |
|
| 83 | + 'sea' => 'application/octet-stream', |
|
| 84 | + 'shtml' => 'text/html', |
|
| 85 | + 'sit' => 'application/x-stuffit', |
|
| 86 | + 'smi' => 'application/smil', |
|
| 87 | + 'smil' => 'application/smil', |
|
| 88 | + 'so' => 'application/octet-stream', |
|
| 89 | + 'swf' => 'application/x-shockwave-flash', |
|
| 90 | + 'tar' => 'application/x-tar', |
|
| 91 | + 'text' => 'text/plain', |
|
| 92 | + 'tgz' => array('application/x-tar', 'application/x-gzip-compressed'), |
|
| 93 | + 'tif' => 'image/tiff', |
|
| 94 | + 'tiff' => 'image/tiff', |
|
| 95 | + 'txt' => 'text/plain', |
|
| 96 | + 'wav' => 'audio/x-wav', |
|
| 97 | + 'wbxml' => 'application/wbxml', |
|
| 98 | + 'wmlc' => 'application/wmlc', |
|
| 99 | + 'word' => array('application/msword', 'application/octet-stream'), |
|
| 100 | + 'xht' => 'application/xhtml+xml', |
|
| 101 | + 'xhtml' => 'application/xhtml+xml', |
|
| 102 | + 'xl' => 'application/excel', |
|
| 103 | + 'xls' => array('application/vnd.ms-excel', 'application/excel', 'application/msexcel'), |
|
| 104 | + 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
|
| 105 | + 'xml' => 'text/xml', |
|
| 106 | + 'xsl' => 'text/xml', |
|
| 107 | + 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'), |
|
| 108 | + ); |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Get a file MIME type by extension. |
|
| 112 | - * <code> |
|
| 113 | - * // Determine the MIME type for the .tar extension |
|
| 114 | - * $mime = File::mime('tar'); |
|
| 115 | - * // Return a default value if the MIME can't be determined |
|
| 116 | - * $mime = File::mime('ext', 'application/octet-stream'); |
|
| 117 | - * </code> |
|
| 118 | - * |
|
| 119 | - * @param string $extension |
|
| 120 | - * @param string $default |
|
| 121 | - * |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - public static function mime($extension, $default = 'application/octet-stream') |
|
| 125 | - { |
|
| 126 | - $mimes = self::$mimes; |
|
| 110 | + /** |
|
| 111 | + * Get a file MIME type by extension. |
|
| 112 | + * <code> |
|
| 113 | + * // Determine the MIME type for the .tar extension |
|
| 114 | + * $mime = File::mime('tar'); |
|
| 115 | + * // Return a default value if the MIME can't be determined |
|
| 116 | + * $mime = File::mime('ext', 'application/octet-stream'); |
|
| 117 | + * </code> |
|
| 118 | + * |
|
| 119 | + * @param string $extension |
|
| 120 | + * @param string $default |
|
| 121 | + * |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + public static function mime($extension, $default = 'application/octet-stream') |
|
| 125 | + { |
|
| 126 | + $mimes = self::$mimes; |
|
| 127 | 127 | |
| 128 | - if (!array_key_exists($extension, $mimes)) { |
|
| 129 | - return $default; |
|
| 130 | - } |
|
| 128 | + if (!array_key_exists($extension, $mimes)) { |
|
| 129 | + return $default; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - return (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension]; |
|
| 133 | - } |
|
| 132 | + return (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension]; |
|
| 133 | + } |
|
| 134 | 134 | } |
@@ -1,184 +1,184 @@ |
||
| 1 | 1 | <?php return array( |
| 2 | 2 | |
| 3 | - // Markup |
|
| 4 | - //////////////////////////////////////////////////////////////////// |
|
| 5 | - |
|
| 6 | - // Whether labels should be automatically computed from name |
|
| 7 | - 'automatic_label' => true, |
|
| 8 | - |
|
| 9 | - // The default form type |
|
| 10 | - 'default_form_type' => 'horizontal', |
|
| 11 | - |
|
| 12 | - // Validation |
|
| 13 | - //////////////////////////////////////////////////////////////////// |
|
| 14 | - |
|
| 15 | - // Whether Former should fetch errors from Session |
|
| 16 | - 'fetch_errors' => true, |
|
| 17 | - |
|
| 18 | - // Whether Former should try to apply Validator rules as attributes |
|
| 19 | - 'live_validation' => true, |
|
| 20 | - |
|
| 21 | - // Whether Former should automatically fetch error messages and |
|
| 22 | - // display them next to the matching fields |
|
| 23 | - 'error_messages' => true, |
|
| 24 | - |
|
| 25 | - // Checkables |
|
| 26 | - //////////////////////////////////////////////////////////////////// |
|
| 27 | - |
|
| 28 | - // Whether checkboxes should always be present in the POST data, |
|
| 29 | - // no matter if you checked them or not |
|
| 30 | - 'push_checkboxes' => false, |
|
| 31 | - |
|
| 32 | - // The value a checkbox will have in the POST array if unchecked |
|
| 33 | - 'unchecked_value' => 0, |
|
| 34 | - |
|
| 35 | - // Required fields |
|
| 36 | - //////////////////////////////////////////////////////////////////// |
|
| 37 | - |
|
| 38 | - // The class to be added to required fields |
|
| 39 | - 'required_class' => 'required', |
|
| 40 | - |
|
| 41 | - // A facultative text to append to the labels of required fields |
|
| 42 | - 'required_text' => '<sup>*</sup>', |
|
| 43 | - |
|
| 44 | - // Translations |
|
| 45 | - //////////////////////////////////////////////////////////////////// |
|
| 46 | - |
|
| 47 | - // Where Former should look for translations |
|
| 48 | - 'translate_from' => 'validation.attributes', |
|
| 49 | - |
|
| 50 | - // Whether text that comes out of the translated |
|
| 51 | - // should be capitalized (ex: email => Email) automatically |
|
| 52 | - 'capitalize_translations' => true, |
|
| 53 | - |
|
| 54 | - // An array of attributes to automatically translate |
|
| 55 | - 'translatable' => array( |
|
| 56 | - 'help', |
|
| 57 | - 'inlineHelp', |
|
| 58 | - 'blockHelp', |
|
| 59 | - 'placeholder', |
|
| 60 | - 'data_placeholder', |
|
| 61 | - 'label', |
|
| 62 | - ), |
|
| 63 | - |
|
| 64 | - // Framework |
|
| 65 | - //////////////////////////////////////////////////////////////////// |
|
| 66 | - |
|
| 67 | - // The framework to be used by Former |
|
| 68 | - 'framework' => 'TwitterBootstrap3', |
|
| 69 | - |
|
| 70 | - 'TwitterBootstrap3' => array( |
|
| 71 | - |
|
| 72 | - // Map Former-supported viewports to Bootstrap 3 equivalents |
|
| 73 | - 'viewports' => array( |
|
| 74 | - 'large' => 'lg', |
|
| 75 | - 'medium' => 'md', |
|
| 76 | - 'small' => 'sm', |
|
| 77 | - 'mini' => 'xs', |
|
| 78 | - ), |
|
| 79 | - // Width of labels for horizontal forms expressed as viewport => grid columns |
|
| 80 | - 'labelWidths' => array( |
|
| 81 | - 'large' => 2, |
|
| 82 | - 'small' => 4, |
|
| 83 | - ), |
|
| 84 | - // HTML markup and classes used by Bootstrap 3 for icons |
|
| 85 | - 'icon' => array( |
|
| 86 | - 'tag' => 'span', |
|
| 87 | - 'set' => 'glyphicon', |
|
| 88 | - 'prefix' => 'glyphicon', |
|
| 89 | - ), |
|
| 90 | - |
|
| 91 | - ), |
|
| 92 | - |
|
| 93 | - 'Nude' => array( // No-framework markup |
|
| 94 | - 'icon' => array( |
|
| 95 | - 'tag' => 'i', |
|
| 96 | - 'set' => null, |
|
| 97 | - 'prefix' => 'icon', |
|
| 98 | - ), |
|
| 99 | - ), |
|
| 100 | - |
|
| 101 | - 'TwitterBootstrap' => array( // Twitter Bootstrap version 2 |
|
| 102 | - 'icon' => array( |
|
| 103 | - 'tag' => 'i', |
|
| 104 | - 'set' => null, |
|
| 105 | - 'prefix' => 'icon', |
|
| 106 | - ), |
|
| 107 | - ), |
|
| 108 | - |
|
| 109 | - 'ZurbFoundation5' => array( |
|
| 110 | - // Map Former-supported viewports to Foundation 5 equivalents |
|
| 111 | - 'viewports' => array( |
|
| 112 | - 'large' => 'large', |
|
| 113 | - 'medium' => null, |
|
| 114 | - 'small' => 'small', |
|
| 115 | - 'mini' => null, |
|
| 116 | - ), |
|
| 117 | - // Width of labels for horizontal forms expressed as viewport => grid columns |
|
| 118 | - 'labelWidths' => array( |
|
| 119 | - 'small' => 3, |
|
| 120 | - ), |
|
| 121 | - // Classes to be applied to wrapped labels in horizontal forms |
|
| 122 | - 'wrappedLabelClasses' => array('right', 'inline'), |
|
| 123 | - // HTML markup and classes used by Foundation 5 for icons |
|
| 124 | - 'icon' => array( |
|
| 125 | - 'tag' => 'i', |
|
| 126 | - 'set' => null, |
|
| 127 | - 'prefix' => 'fi', |
|
| 128 | - ), |
|
| 129 | - // CSS for inline validation errors |
|
| 130 | - 'error_classes' => array('class' => 'error'), |
|
| 131 | - ), |
|
| 132 | - |
|
| 133 | - 'ZurbFoundation4' => array( |
|
| 134 | - // Foundation 4 also has an experimental "medium" breakpoint |
|
| 135 | - // explained at http://foundation.zurb.com/docs/components/grid.html |
|
| 136 | - 'viewports' => array( |
|
| 137 | - 'large' => 'large', |
|
| 138 | - 'medium' => null, |
|
| 139 | - 'small' => 'small', |
|
| 140 | - 'mini' => null, |
|
| 141 | - ), |
|
| 142 | - // Width of labels for horizontal forms expressed as viewport => grid columns |
|
| 143 | - 'labelWidths' => array( |
|
| 144 | - 'small' => 3, |
|
| 145 | - ), |
|
| 146 | - // Classes to be applied to wrapped labels in horizontal forms |
|
| 147 | - 'wrappedLabelClasses' => array('right', 'inline'), |
|
| 148 | - // HTML markup and classes used by Foundation 4 for icons |
|
| 149 | - 'icon' => array( |
|
| 150 | - 'tag' => 'i', |
|
| 151 | - 'set' => 'general', |
|
| 152 | - 'prefix' => 'foundicon', |
|
| 153 | - ), |
|
| 154 | - // CSS for inline validation errors |
|
| 155 | - 'error_classes' => array('class' => 'alert-box radius warning'), |
|
| 156 | - ), |
|
| 157 | - |
|
| 158 | - 'ZurbFoundation' => array( // Foundation 3 |
|
| 159 | - 'viewports' => array( |
|
| 160 | - 'large' => '', |
|
| 161 | - 'medium' => null, |
|
| 162 | - 'small' => 'mobile-', |
|
| 163 | - 'mini' => null, |
|
| 164 | - ), |
|
| 165 | - // Width of labels for horizontal forms expressed as viewport => grid columns |
|
| 166 | - 'labelWidths' => array( |
|
| 167 | - 'large' => 2, |
|
| 168 | - 'small' => 4, |
|
| 169 | - ), |
|
| 170 | - // Classes to be applied to wrapped labels in horizontal forms |
|
| 171 | - 'wrappedLabelClasses' => array('right', 'inline'), |
|
| 172 | - // HTML markup and classes used by Foundation 3 for icons |
|
| 173 | - 'icon' => array( |
|
| 174 | - 'tag' => 'i', |
|
| 175 | - 'set' => null, |
|
| 176 | - 'prefix' => 'fi', |
|
| 177 | - ), |
|
| 178 | - // CSS for inline validation errors |
|
| 179 | - // should work for Zurb 2 and 3 |
|
| 180 | - 'error_classes' => array('class' => 'alert-box alert error'), |
|
| 181 | - ), |
|
| 3 | + // Markup |
|
| 4 | + //////////////////////////////////////////////////////////////////// |
|
| 5 | + |
|
| 6 | + // Whether labels should be automatically computed from name |
|
| 7 | + 'automatic_label' => true, |
|
| 8 | + |
|
| 9 | + // The default form type |
|
| 10 | + 'default_form_type' => 'horizontal', |
|
| 11 | + |
|
| 12 | + // Validation |
|
| 13 | + //////////////////////////////////////////////////////////////////// |
|
| 14 | + |
|
| 15 | + // Whether Former should fetch errors from Session |
|
| 16 | + 'fetch_errors' => true, |
|
| 17 | + |
|
| 18 | + // Whether Former should try to apply Validator rules as attributes |
|
| 19 | + 'live_validation' => true, |
|
| 20 | + |
|
| 21 | + // Whether Former should automatically fetch error messages and |
|
| 22 | + // display them next to the matching fields |
|
| 23 | + 'error_messages' => true, |
|
| 24 | + |
|
| 25 | + // Checkables |
|
| 26 | + //////////////////////////////////////////////////////////////////// |
|
| 27 | + |
|
| 28 | + // Whether checkboxes should always be present in the POST data, |
|
| 29 | + // no matter if you checked them or not |
|
| 30 | + 'push_checkboxes' => false, |
|
| 31 | + |
|
| 32 | + // The value a checkbox will have in the POST array if unchecked |
|
| 33 | + 'unchecked_value' => 0, |
|
| 34 | + |
|
| 35 | + // Required fields |
|
| 36 | + //////////////////////////////////////////////////////////////////// |
|
| 37 | + |
|
| 38 | + // The class to be added to required fields |
|
| 39 | + 'required_class' => 'required', |
|
| 40 | + |
|
| 41 | + // A facultative text to append to the labels of required fields |
|
| 42 | + 'required_text' => '<sup>*</sup>', |
|
| 43 | + |
|
| 44 | + // Translations |
|
| 45 | + //////////////////////////////////////////////////////////////////// |
|
| 46 | + |
|
| 47 | + // Where Former should look for translations |
|
| 48 | + 'translate_from' => 'validation.attributes', |
|
| 49 | + |
|
| 50 | + // Whether text that comes out of the translated |
|
| 51 | + // should be capitalized (ex: email => Email) automatically |
|
| 52 | + 'capitalize_translations' => true, |
|
| 53 | + |
|
| 54 | + // An array of attributes to automatically translate |
|
| 55 | + 'translatable' => array( |
|
| 56 | + 'help', |
|
| 57 | + 'inlineHelp', |
|
| 58 | + 'blockHelp', |
|
| 59 | + 'placeholder', |
|
| 60 | + 'data_placeholder', |
|
| 61 | + 'label', |
|
| 62 | + ), |
|
| 63 | + |
|
| 64 | + // Framework |
|
| 65 | + //////////////////////////////////////////////////////////////////// |
|
| 66 | + |
|
| 67 | + // The framework to be used by Former |
|
| 68 | + 'framework' => 'TwitterBootstrap3', |
|
| 69 | + |
|
| 70 | + 'TwitterBootstrap3' => array( |
|
| 71 | + |
|
| 72 | + // Map Former-supported viewports to Bootstrap 3 equivalents |
|
| 73 | + 'viewports' => array( |
|
| 74 | + 'large' => 'lg', |
|
| 75 | + 'medium' => 'md', |
|
| 76 | + 'small' => 'sm', |
|
| 77 | + 'mini' => 'xs', |
|
| 78 | + ), |
|
| 79 | + // Width of labels for horizontal forms expressed as viewport => grid columns |
|
| 80 | + 'labelWidths' => array( |
|
| 81 | + 'large' => 2, |
|
| 82 | + 'small' => 4, |
|
| 83 | + ), |
|
| 84 | + // HTML markup and classes used by Bootstrap 3 for icons |
|
| 85 | + 'icon' => array( |
|
| 86 | + 'tag' => 'span', |
|
| 87 | + 'set' => 'glyphicon', |
|
| 88 | + 'prefix' => 'glyphicon', |
|
| 89 | + ), |
|
| 90 | + |
|
| 91 | + ), |
|
| 92 | + |
|
| 93 | + 'Nude' => array( // No-framework markup |
|
| 94 | + 'icon' => array( |
|
| 95 | + 'tag' => 'i', |
|
| 96 | + 'set' => null, |
|
| 97 | + 'prefix' => 'icon', |
|
| 98 | + ), |
|
| 99 | + ), |
|
| 100 | + |
|
| 101 | + 'TwitterBootstrap' => array( // Twitter Bootstrap version 2 |
|
| 102 | + 'icon' => array( |
|
| 103 | + 'tag' => 'i', |
|
| 104 | + 'set' => null, |
|
| 105 | + 'prefix' => 'icon', |
|
| 106 | + ), |
|
| 107 | + ), |
|
| 108 | + |
|
| 109 | + 'ZurbFoundation5' => array( |
|
| 110 | + // Map Former-supported viewports to Foundation 5 equivalents |
|
| 111 | + 'viewports' => array( |
|
| 112 | + 'large' => 'large', |
|
| 113 | + 'medium' => null, |
|
| 114 | + 'small' => 'small', |
|
| 115 | + 'mini' => null, |
|
| 116 | + ), |
|
| 117 | + // Width of labels for horizontal forms expressed as viewport => grid columns |
|
| 118 | + 'labelWidths' => array( |
|
| 119 | + 'small' => 3, |
|
| 120 | + ), |
|
| 121 | + // Classes to be applied to wrapped labels in horizontal forms |
|
| 122 | + 'wrappedLabelClasses' => array('right', 'inline'), |
|
| 123 | + // HTML markup and classes used by Foundation 5 for icons |
|
| 124 | + 'icon' => array( |
|
| 125 | + 'tag' => 'i', |
|
| 126 | + 'set' => null, |
|
| 127 | + 'prefix' => 'fi', |
|
| 128 | + ), |
|
| 129 | + // CSS for inline validation errors |
|
| 130 | + 'error_classes' => array('class' => 'error'), |
|
| 131 | + ), |
|
| 132 | + |
|
| 133 | + 'ZurbFoundation4' => array( |
|
| 134 | + // Foundation 4 also has an experimental "medium" breakpoint |
|
| 135 | + // explained at http://foundation.zurb.com/docs/components/grid.html |
|
| 136 | + 'viewports' => array( |
|
| 137 | + 'large' => 'large', |
|
| 138 | + 'medium' => null, |
|
| 139 | + 'small' => 'small', |
|
| 140 | + 'mini' => null, |
|
| 141 | + ), |
|
| 142 | + // Width of labels for horizontal forms expressed as viewport => grid columns |
|
| 143 | + 'labelWidths' => array( |
|
| 144 | + 'small' => 3, |
|
| 145 | + ), |
|
| 146 | + // Classes to be applied to wrapped labels in horizontal forms |
|
| 147 | + 'wrappedLabelClasses' => array('right', 'inline'), |
|
| 148 | + // HTML markup and classes used by Foundation 4 for icons |
|
| 149 | + 'icon' => array( |
|
| 150 | + 'tag' => 'i', |
|
| 151 | + 'set' => 'general', |
|
| 152 | + 'prefix' => 'foundicon', |
|
| 153 | + ), |
|
| 154 | + // CSS for inline validation errors |
|
| 155 | + 'error_classes' => array('class' => 'alert-box radius warning'), |
|
| 156 | + ), |
|
| 157 | + |
|
| 158 | + 'ZurbFoundation' => array( // Foundation 3 |
|
| 159 | + 'viewports' => array( |
|
| 160 | + 'large' => '', |
|
| 161 | + 'medium' => null, |
|
| 162 | + 'small' => 'mobile-', |
|
| 163 | + 'mini' => null, |
|
| 164 | + ), |
|
| 165 | + // Width of labels for horizontal forms expressed as viewport => grid columns |
|
| 166 | + 'labelWidths' => array( |
|
| 167 | + 'large' => 2, |
|
| 168 | + 'small' => 4, |
|
| 169 | + ), |
|
| 170 | + // Classes to be applied to wrapped labels in horizontal forms |
|
| 171 | + 'wrappedLabelClasses' => array('right', 'inline'), |
|
| 172 | + // HTML markup and classes used by Foundation 3 for icons |
|
| 173 | + 'icon' => array( |
|
| 174 | + 'tag' => 'i', |
|
| 175 | + 'set' => null, |
|
| 176 | + 'prefix' => 'fi', |
|
| 177 | + ), |
|
| 178 | + // CSS for inline validation errors |
|
| 179 | + // should work for Zurb 2 and 3 |
|
| 180 | + 'error_classes' => array('class' => 'alert-box alert error'), |
|
| 181 | + ), |
|
| 182 | 182 | |
| 183 | 183 | |
| 184 | 184 | ); |
@@ -12,128 +12,127 @@ |
||
| 12 | 12 | class File extends Field |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * The maximum file size |
|
| 17 | - * |
|
| 18 | - * @var integer |
|
| 19 | - */ |
|
| 20 | - private $maxSize; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * An array of mime groups to use as shortcuts |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - private $mimeGroups = array('audio', 'video', 'image'); |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * A list of properties to be injected in the attributes |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected $injectedProperties = array('type', 'name'); |
|
| 35 | - |
|
| 36 | - //////////////////////////////////////////////////////////////////// |
|
| 37 | - /////////////////////////// CORE METHODS /////////////////////////// |
|
| 38 | - //////////////////////////////////////////////////////////////////// |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Easier arguments order for hidden fields |
|
| 42 | - * |
|
| 43 | - * @param Container $app The Illuminate Container |
|
| 44 | - * @param string $type file |
|
| 45 | - * @param string $name Field name |
|
| 46 | - * @param string $label Its label |
|
| 47 | - * @param string $value Its value |
|
| 48 | - * @param array $attributes Attributes |
|
| 49 | - */ |
|
| 50 | - public function __construct(Container $app, $type, $name, $label, $value, $attributes) |
|
| 51 | - { |
|
| 52 | - // Multiple files field |
|
| 53 | - if ($type == 'files') { |
|
| 54 | - $attributes['multiple'] = 'true'; |
|
| 55 | - $type = 'file'; |
|
| 56 | - $name = $name.'[]'; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - parent::__construct($app, $type, $name, $label, $value, $attributes); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Prints out the current tag |
|
| 64 | - * |
|
| 65 | - * @return string An input file tag |
|
| 66 | - */ |
|
| 67 | - public function render() |
|
| 68 | - { |
|
| 69 | - // Maximum file size |
|
| 70 | - $hidden = $this->maxSize |
|
| 71 | - ? HtmlInput::hidden('MAX_FILE_SIZE', $this->maxSize) |
|
| 72 | - : null; |
|
| 73 | - |
|
| 74 | - return $hidden.parent::render(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - //////////////////////////////////////////////////////////////////// |
|
| 78 | - ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 79 | - //////////////////////////////////////////////////////////////////// |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Set which types of files are accepted by the file input |
|
| 83 | - |
|
| 84 | - */ |
|
| 85 | - public function accept() |
|
| 86 | - { |
|
| 87 | - $mimes = array(); |
|
| 88 | - |
|
| 89 | - // Transform all extensions/groups to mime types |
|
| 90 | - foreach (func_get_args() as $mime) { |
|
| 91 | - |
|
| 92 | - // Shortcuts and extensions |
|
| 93 | - if (in_array($mime, $this->mimeGroups)) { |
|
| 94 | - $mime .= '/*'; |
|
| 95 | - } |
|
| 96 | - $mime = LaravelFile::mime($mime, $mime); |
|
| 97 | - |
|
| 98 | - $mimes[] = $mime; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // Add accept attribute by concatenating the mimes |
|
| 102 | - $this->attributes['accept'] = implode(',', $mimes); |
|
| 103 | - |
|
| 104 | - return $this; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Set a maximum size for files |
|
| 109 | - * |
|
| 110 | - * @param integer $size A maximum size |
|
| 111 | - * @param string $units The size's unit |
|
| 112 | - */ |
|
| 113 | - public function max($size, $units = 'KB') |
|
| 114 | - { |
|
| 115 | - // Bytes or bits ? |
|
| 116 | - $unit = substr($units, -1); |
|
| 117 | - $base = 1024; |
|
| 118 | - if ($unit == 'b') { |
|
| 119 | - $size = $size / 8; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Convert |
|
| 123 | - switch ($units[0]) { |
|
| 124 | - case 'K': |
|
| 125 | - $size = $size * $base; |
|
| 126 | - break; |
|
| 127 | - case 'M': |
|
| 128 | - $size = $size * pow($base, 2); |
|
| 129 | - break; |
|
| 130 | - case 'G': |
|
| 131 | - $size = $size * pow($base, 3); |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - $this->maxSize = (int) $size; |
|
| 136 | - |
|
| 137 | - return $this; |
|
| 138 | - } |
|
| 15 | + /** |
|
| 16 | + * The maximum file size |
|
| 17 | + * |
|
| 18 | + * @var integer |
|
| 19 | + */ |
|
| 20 | + private $maxSize; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * An array of mime groups to use as shortcuts |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + private $mimeGroups = array('audio', 'video', 'image'); |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * A list of properties to be injected in the attributes |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected $injectedProperties = array('type', 'name'); |
|
| 35 | + |
|
| 36 | + //////////////////////////////////////////////////////////////////// |
|
| 37 | + /////////////////////////// CORE METHODS /////////////////////////// |
|
| 38 | + //////////////////////////////////////////////////////////////////// |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Easier arguments order for hidden fields |
|
| 42 | + * |
|
| 43 | + * @param Container $app The Illuminate Container |
|
| 44 | + * @param string $type file |
|
| 45 | + * @param string $name Field name |
|
| 46 | + * @param string $label Its label |
|
| 47 | + * @param string $value Its value |
|
| 48 | + * @param array $attributes Attributes |
|
| 49 | + */ |
|
| 50 | + public function __construct(Container $app, $type, $name, $label, $value, $attributes) |
|
| 51 | + { |
|
| 52 | + // Multiple files field |
|
| 53 | + if ($type == 'files') { |
|
| 54 | + $attributes['multiple'] = 'true'; |
|
| 55 | + $type = 'file'; |
|
| 56 | + $name = $name.'[]'; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + parent::__construct($app, $type, $name, $label, $value, $attributes); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Prints out the current tag |
|
| 64 | + * |
|
| 65 | + * @return string An input file tag |
|
| 66 | + */ |
|
| 67 | + public function render() |
|
| 68 | + { |
|
| 69 | + // Maximum file size |
|
| 70 | + $hidden = $this->maxSize |
|
| 71 | + ? HtmlInput::hidden('MAX_FILE_SIZE', $this->maxSize) |
|
| 72 | + : null; |
|
| 73 | + |
|
| 74 | + return $hidden.parent::render(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + //////////////////////////////////////////////////////////////////// |
|
| 78 | + ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 79 | + //////////////////////////////////////////////////////////////////// |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Set which types of files are accepted by the file input |
|
| 83 | + */ |
|
| 84 | + public function accept() |
|
| 85 | + { |
|
| 86 | + $mimes = array(); |
|
| 87 | + |
|
| 88 | + // Transform all extensions/groups to mime types |
|
| 89 | + foreach (func_get_args() as $mime) { |
|
| 90 | + |
|
| 91 | + // Shortcuts and extensions |
|
| 92 | + if (in_array($mime, $this->mimeGroups)) { |
|
| 93 | + $mime .= '/*'; |
|
| 94 | + } |
|
| 95 | + $mime = LaravelFile::mime($mime, $mime); |
|
| 96 | + |
|
| 97 | + $mimes[] = $mime; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // Add accept attribute by concatenating the mimes |
|
| 101 | + $this->attributes['accept'] = implode(',', $mimes); |
|
| 102 | + |
|
| 103 | + return $this; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Set a maximum size for files |
|
| 108 | + * |
|
| 109 | + * @param integer $size A maximum size |
|
| 110 | + * @param string $units The size's unit |
|
| 111 | + */ |
|
| 112 | + public function max($size, $units = 'KB') |
|
| 113 | + { |
|
| 114 | + // Bytes or bits ? |
|
| 115 | + $unit = substr($units, -1); |
|
| 116 | + $base = 1024; |
|
| 117 | + if ($unit == 'b') { |
|
| 118 | + $size = $size / 8; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // Convert |
|
| 122 | + switch ($units[0]) { |
|
| 123 | + case 'K': |
|
| 124 | + $size = $size * $base; |
|
| 125 | + break; |
|
| 126 | + case 'M': |
|
| 127 | + $size = $size * pow($base, 2); |
|
| 128 | + break; |
|
| 129 | + case 'G': |
|
| 130 | + $size = $size * pow($base, 3); |
|
| 131 | + break; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + $this->maxSize = (int) $size; |
|
| 135 | + |
|
| 136 | + return $this; |
|
| 137 | + } |
|
| 139 | 138 | } |