コード例 #1
0
ファイル: ControlGroup.php プロジェクト: iyoworks/former
 /**
  * Opens a control group
  *
  * @return string Opening tag
  */
 private function open()
 {
     // If any errors, set state to errors
     $errors = Former::getErrors();
     if ($errors) {
         $this->state('error');
     }
     // Retrieve state and append it to classes
     if ($this->state) {
         $this->attributes = Helpers::addClass($this->attributes, $this->state);
     }
     // Required state
     if (Former::field()->isRequired()) {
         $this->attributes = Helpers::addClass($this->attributes, Config::get('required_class'));
     }
     return '<div' . HTML::attributes($this->attributes) . '>';
 }
コード例 #2
0
ファイル: Helpers.php プロジェクト: raftalks/former
 /**
  * Translates a string by trying several fallbacks
  *
  * @param  string $key      The key to translate
  * @param  string $fallback The ultimate fallback
  * @return string           A translated string
  */
 public static function translate($key, $fallback = null)
 {
     // If nothing was given, return nothing, bitch
     if (!$key) {
         return null;
     }
     // If no fallback, use the key
     if (!$fallback) {
         $fallback = $key;
     }
     // Assure we don't already have a Lang object
     if ($key instanceof Lang) {
         return $key->get();
     }
     // Search for the key itself
     $translation = Lang::line($key)->get(null, '');
     // If not found, search in the field attributes
     if (!$translation) {
         $translation = Lang::line(Config::get('translate_from') . '.' . $key)->get(null, $fallback);
     }
     return ucfirst($translation);
 }
コード例 #3
0
ファイル: Field.php プロジェクト: raftalks/former
 /**
  * Set up a Field instance
  *
  * @param string $type A field type
  */
 public function __construct($type, $name, $label, $value, $attributes)
 {
     // Set base parameters
     $this->attributes = (array) $attributes;
     $this->label = $label;
     $this->name = $name;
     $this->type = $type;
     $this->value = $value;
     // Set magic parameters (repopulated value, translated label, etc)
     if (Config::get('automatic_label')) {
         $this->ponder($name, $label);
     }
     if ($type != 'password') {
         $this->value = $this->repopulate();
     }
     if (Config::get('live_validation')) {
         $this->addRules();
     }
     // Link Control group
     if (Framework::isnt(null)) {
         $this->controlGroup = new ControlGroup($this->label);
     }
 }
コード例 #4
0
ファイル: Framework.php プロジェクト: iyoworks/former
 /**
  * Change the framework currently being used by Former
  *
  * @param  string $framework A framework, or null for none
  */
 public static function useFramework($framework = null)
 {
     if (in_array($framework, array('bootstrap', 'zurb')) or is_null($framework)) {
         Config::set('framework', $framework);
     }
     return static::current();
 }
コード例 #5
0
ファイル: Config.php プロジェクト: iyoworks/former
 /**
  * Fetch options from both Former and the user
  */
 public function __construct()
 {
     $defaultOptions = Conf::get('former::former');
     $userOptions = (array) Conf::get('former');
     static::$options = array_merge($defaultOptions, $userOptions);
 }
コード例 #6
0
ファイル: start.php プロジェクト: raftalks/former
<?php

use Former\Config;
use Former\Framework;
// Loading Former -------------------------------------------------- /
Autoloader::namespaces(array('Former' => Bundle::path('former') . 'libraries'));
// Loading Former configuration ------------------------------------ /
// Fetch configuration files
new Config();
// Set default framework
Framework::useFramework(Config::get('framework'));
コード例 #7
0
ファイル: Helpers.php プロジェクト: iyoworks/former
 public static function renderLabel($label, $field)
 {
     // Get the label and its informations
     extract($label);
     // Add classes to the attributes
     $attributes = Framework::getLabelClasses($attributes);
     // Append required text
     if ($field->isRequired()) {
         $label .= Config::get('required_text');
     }
     // Get the field name to link the label to it
     if ($field->isCheckable()) {
         return '<label' . HTML::attributes($attributes) . '>' . $label . '</label>';
     }
     return \Form::label($field->name, $label, $attributes);
 }