Exemplo n.º 1
0
 function __call($method, $args)
 {
     preg_match('/^add(.+)$/', $method, $matches);
     $class = 'Wtk_Form_Control_' . $matches[1];
     if (!@class_exists($class)) {
         /* Le contrôle n'existe pas, alors on délègue la créations d'enfant
          * courant. */
         return parent::__call($method, $args);
     }
     $instance = $i = array_shift($args);
     if (is_string($instance)) {
         try {
             $instance = $this->model->getInstance($instance);
         } catch (Exception $e) {
             $instance = null;
         }
     }
     if (!$instance) {
         throw new Exception("Can't retrieve instance '" . $i . "' " . "in model '" . $this->model->id . "'.");
     }
     $path = $instance->path;
     array_unshift($args, $instance);
     /* Ne fonctionne pas… */
     /* $el = wtk_new($class, $args); */
     $cargs = wtk_args_string("args", $args);
     $code = "\$el = new " . $class . "(" . implode(",", $cargs) . ");";
     eval($code);
     foreach ($this->model->constraints as $cons) {
         if ($cons->getInstance()->path == $instance->path) {
             $el->addFlags('constrained', $cons->getFlags());
         }
     }
     return $this->addChild($el);
 }
Exemplo n.º 2
0
 function __call($method, $args)
 {
     if (preg_match("/^add(.*)\$/", $method, $matches)) {
         $class = "Wtk_Form_Model_Instance_" . $matches[1];
         $cargs = wtk_args_string('args', $args);
         $code = "return new " . $class . "(" . implode(', ', $cargs) . ");";
         $ins = eval($code);
         return $this->addChild($ins);
     }
 }
Exemplo n.º 3
0
function wtk_new($class, $args)
{
    if (!class_exists($class)) {
        throw new Exception("Class {$class} inexistant");
    }
    $code = '$obj = new ' . $class . ' (' . implode(', ', wtk_args_string('args', $args)) . ');';
    eval($code);
    return $obj;
}