Beispiel #1
0
 public function render()
 {
     if ($this->callback) {
         $callback = Cogear::prepareCallback($this->callback);
         $this->setValues(call_user_func($callback));
     }
     $this->setAttributes();
     $code = array();
     foreach ($this->values as $key => $value) {
         $attributes = $this->attributes;
         $attributes['value'] = $key;
         if ($key === $this->value) {
             $attributes['checked'] = 'checked';
         }
         $code[] = HTML::tag('input', $attributes) . $value;
     }
     $code = implode("<br/>", $code);
     if ($this->wrapper) {
         $tpl = new Template($this->wrapper);
         $tpl->assign($this->attributes);
         $tpl->code = $code;
         $code = $tpl->render();
     }
     return $code;
 }
Beispiel #2
0
 /**
  * Initialize elements
  */
 private function init()
 {
     if ($this->is_init) {
         return;
     }
     event('form.init', $this);
     event('form.init.' . $this->options->name, $this);
     if ($this->options->elements) {
         foreach ($this->options->elements as $name => $config) {
             $this->add($name, $config);
         }
         if ($this->callback && ($callback = Cogear::prepareCallback($this->callback))) {
             if ($this->result = $this->result()) {
                 call_user_func_array($callback, array($this));
             }
         }
     }
     $this->is_init = TRUE;
 }
Beispiel #3
0
 /**
  * Get Gear name
  *
  * @return  string
  */
 protected function getGear()
 {
     return $this->gear ? $this->gear : ($this->gear = Cogear::prepareGearNameFromClass($this->reflection->getName()));
 }
Beispiel #4
0
 /**
  * Get instance
  *
  * @return Cogear
  */
 public static function getInstance()
 {
     return self::$_instance instanceof self ? self::$_instance : (self::$_instance = new self());
 }
Beispiel #5
0
 *
 * @param   $class  Class name.
 * @return  boolean
 */
function autoload($class)
{
    $filename = str_replace('_', DS, $class);
    if ($path = find($filename . EXT)) {
        include $path;
        return TRUE;
    }
    return FALSE;
}
// Register with autoload
spl_autoload_register('autoload');
$cogear = Cogear::getInstance();
// Some root classes are needed to be preloaded
$cogear->request = new Request();
// Set host
$host = $cogear->request->get('HTTP_HOST');
// Defince site folder
// Check if main
if (substr_count($host, '.') > 1) {
    if (!is_dir(SITES . DS . $host)) {
        list($subdomain, $host) = preg_split('#[\\.]+#', $host, 2, PREG_SPLIT_NO_EMPTY);
        define('SUBDOMAIN', $subdomain);
    }
}
defined('SITE') or is_dir(SITES . DS . $host) && define('SITE', SITES . DS . $host) or define('SITE', DEFAULT_SITE);
define('SITE_GEARS', SITE . DS . GEARS_FOLDER);
$cogear->config = new Config(SITE . DS . 'settings' . EXT);
Beispiel #6
0
 /**
  * Initialize elements
  */
 public function init()
 {
     if ($this->initialized) {
         return;
     }
     event('form.init', $this);
     event('form.' . $this->name . '.init', $this);
     $this->is_ajaxed = isset($_REQUEST['form']) && $_REQUEST['form'] == $this->name;
     $elements = array();
     foreach ($this->elements as $name => $config) {
         $this->addElement($name, $config);
     }
     $this->initialized = TRUE;
     if ($this->callback && ($callback = Cogear::prepareCallback($this->callback))) {
         if ($result = $this->result()) {
             call_user_func_array($callback, array($result));
         } else {
             return $this->render();
         }
     }
 }
Beispiel #7
0
 /**
  * Generate hash for user
  *
  * @param object $user
  */
 public function genHash()
 {
     return md5($this->password . Cogear::key());
 }