-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from garyttierney/master
Virtual Elements, Compatability with Symfony 2.2, Validation Updates
- Loading branch information
Showing
5 changed files
with
151 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
|
||
namespace PPI\Form\Element; | ||
|
||
/** | ||
* An abstract Element which encapsulates the rendering of several inputs and transforms the independent data into something | ||
* suitable for validation. | ||
* | ||
* Class Virtual | ||
* @package PPI\Form\Element | ||
*/ | ||
abstract class Virtual extends Element | ||
{ | ||
protected $elements = array(); | ||
|
||
public function addElement(Element $element) | ||
{ | ||
$this->elements[] = $element; | ||
} | ||
|
||
public function __construct($options = array()) | ||
{ | ||
parent::__construct($options); | ||
} | ||
|
||
/** | ||
* Render the tag | ||
* | ||
* @return string | ||
*/ | ||
public function render() | ||
{ | ||
$parts = array(); | ||
|
||
foreach($this->elements as $element) { | ||
$parts[] = $element->render(); | ||
} | ||
|
||
return implode("\n", $parts); | ||
} | ||
|
||
/** | ||
* Takes an array of input and returns a string. Should be used when you have 2 elements which should be concatenated into 1 variable. | ||
* | ||
* For example, if you want a TimeElement which allows the user to choose hours via a select element, and minutes via a select element | ||
* then you should get the input as an array (input_x[0] -- hours, input_x[1] -- minutes) and implement this method | ||
* to join both of those inputs. | ||
* | ||
* @param array $data | ||
* @return string | ||
*/ | ||
public abstract function transformInput(array $data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters