Пример #1
0
 function test_forms_from_model()
 {
     $manager = minim('orm')->register('dummy');
     $manager->int('foo')->text('bar');
     $this->assertEqual(2, count($manager->_fields), "Manager should have 2 fields");
     $form = forms()->from_model('dummy');
     $this->assertEqual(2, count($form->_fields), "Form should have 2 fields");
 }
Пример #2
0
 function test_minim_get_plugin()
 {
     $minim = new Minim();
     $this->assertTrue($minim !== minim());
     $minim->plugin_paths = array(path(dirname(__FILE__), 'res'));
     $plugin =& $minim->get_plugin('dummy');
     $class = get_class($plugin);
     $this->assertTrue($class == 'DummyPlugin', "Class mismatch: {$class}");
 }
Пример #3
0
 function enable()
 {
     minim('routing')->view_paths[] = path(dirname(__FILE__), 'views');
     minim('templates')->template_paths[] = path(dirname(__FILE__), 'templates');
     // point to routing and pagination helpers
     $paths =& minim('templates')->helper_paths;
     $paths = array_unique(array_merge($paths, array(path(minim('auth')->plugin_path, 'helpers.php'), path(minim('routing')->plugin_path, 'helpers.php'), path(minim('pagination')->plugin_path, 'helpers.php'))));
     // set up admin urls
     minim('routing')->url('^admin$')->maps_to('admin-default')->url('^admin/models$')->maps_to('admin-models')->url('^admin/models/(?P<model>[a-zA-Z]+)/(?P<action>new)$')->maps_to('admin-model-edit')->url('^admin/models/(?P<model>[a-zA-Z]+)/(?P<id>\\d+)$')->maps_to('admin-model-edit')->url('^admin/models/(?P<model>[a-zA-Z]+)/(?P<id>\\d+)/(?P<action>delete)$')->maps_to('admin-model-edit')->url('^admin/models/(?P<model>[a-zA-Z]+)$')->maps_to('admin-model-list')->url('^admin/login$')->maps_to('admin-login');
 }
Пример #4
0
 function __construct($params, $auth)
 {
     $this->_auth = $auth;
     $this->_orm = minim('orm');
     if (!$this->_orm->_backend) {
         throw new Minim_Auth_Exception("ORM Auth backend error: ORM not configured");
     }
     try {
         $this->_orm->register('user')->int('id', array('auto_increment' => TRUE))->text('name', array('max_length' => 20))->text('password_hash', array('max_length' => 32));
     } catch (Minim_Orm_Exception $moe) {
         // model already registered
         // TODO - could be a problem
     }
 }
Пример #5
0
 function test_admin_model_edit()
 {
     minim('admin')->enable();
     $orm = minim('orm');
     $orm->set_backend('sqlite', array('database' => ':memory:'));
     $orm->_backend->execute_query('CREATE TABLE baz (id INT);', array());
     $orm->register('baz')->int('id');
     // save a test model
     $baz = minim('orm')->baz;
     $baz->create(array('id' => 1))->save();
     $this->assertEqual(1, $baz->get(array('id' => 1))->id);
     // request the model edit page
     $GLOBALS['_SERVER'] = array('REQUEST_URI' => 'http://localhost/admin/models/baz/1');
     //minim('routing')->route_request();
     //$this->assertOutputContains('flobadob');
 }
Пример #6
0
 function from_model($manager, $model = NULL)
 {
     $form = new Minim_Form($this);
     try {
         $manager = minim('orm')->{$manager};
     } catch (Minim_Orm_Exception $e) {
         throw new Minim_Forms_Exception("Cannot create form from non-existant model {$manager}");
     }
     foreach ($manager->_fields as $name => $field) {
         // try to get a widget for the form field:
         // widgets can be overridden later
         $widget = $field->widget();
         // add a form field
         $form->{$widget}($name, array_merge(array('label' => ucfirst($name)), $field->params));
     }
     error_log(print_r($form, TRUE));
     return $form;
 }
Пример #7
0
        $config = realpath(join(DIRECTORY_SEPARATOR, array(getcwd(), $options['c'])));
    }
    if (is_file($config)) {
        require $config;
    } else {
        die("Config file {$options['c']} not found");
    }
} else {
    require 'config.php';
}
$file = realpath(@$options['f']);
if (!$file) {
    $file = realpath(join(DIRECTORY_SEPARATOR, array(getcwd(), @$options['f'])));
}
$fh = STDOUT;
if (is_file($file)) {
    print "{$file} already exists, overwrite? [yN] ";
    $response = fscanf(STDIN, '%s');
    if (strtolower($response[0]) !== 'y') {
        print "Aborting\n";
        exit;
    }
    $fh = fopen($file, 'w');
}
$base = '';
if (isset(minim()->webroot)) {
    $base = minim()->webroot;
}
fputs($fh, "RewriteEngine On\n");
$rules = minim('routing')->mod_rewrite_rules($base);
fputs($fh, join("\n", $rules));
Пример #8
0
<?php

$models = array();
$pattern = '/->register\\(([\'"])(.*?)\\1/';
foreach (minim('orm')->model_paths as $path) {
    $dir = new DirectoryIterator($path);
    foreach ($dir as $file) {
        $filename = $file->getPathname();
        if (substr($filename, -4) == '.php' and preg_match($pattern, file_get_contents($filename), $m)) {
            $models[] = $m[2];
        }
    }
}
minim('templates')->render('models', array('models' => $models));
Пример #9
0
function url_for($route, $params)
{
    return minim('routing')->url_for($route, $params);
}
Пример #10
0
<?php

minim('templates')->render('home', array('logo_is_h1' => TRUE));
Пример #11
0
function paginate($items)
{
    return minim('pagination')->paginate($items);
}
Пример #12
0
<?php

minim('orm')->register('test');
Пример #13
0
<?php

minim('templates')->render('default', array());
Пример #14
0
function logged_in_user()
{
    return minim('auth')->get_logged_in_user();
}
Пример #15
0
$this->end();
?>

<?php 
$this->set('page_content');
?>
    <table>
      <thead>
        <tr>
          <th scope="col">Model</th>
        </tr>
      </thead>
      <tbody>
      <?php 
foreach ($models as $model) {
    ?>
        <tr>
          <td><a href="<?php 
    echo minim('routing')->url_for('admin-model-list', array('model' => $model));
    ?>
"><?php 
    echo $model;
    ?>
</a></td>
      <?php 
}
?>
      </tbody>
    </table>
<?php 
$this->end();
Пример #16
0
 function tear_down()
 {
     minim('orm')->_backend->execute_query('DELETE FROM user', array());
     minim('orm')->_backend->execute_query('DROP TABLE IF EXISTS user', array());
 }
Пример #17
0
 function __get($name)
 {
     if (array_key_exists($name, $this->_fields)) {
         $field =& $this->_fields[$name];
         return $field;
     }
     minim()->log("MinimForm {$this->_name} has no field named {$name}");
     return NULL;
 }
Пример #18
0
    if (!$model) {
        minim('templates')->render_404();
        return;
    }
    if ($action == 'delete') {
        $model->delete();
        minim('user_messaging')->info("Deleted {$model_name} #{$id}");
        minim('routing')->redirect('admin/model-list', array());
    }
    $params = $model;
}
$form = minim('new_forms')->from_model($model_name, $params);
$errors = NULL;
if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
    $data = $_POST;
    if ($action == 'new') {
        unset($data['id']);
    }
    $form->from($data);
    if ($form->isValid()) {
        $model = minim('orm')->{$model_name}->from($form->getData());
        $model->save();
        minim('user_messaging')->info("{$model_name} saved");
        minim('routing')->redirect('admin/model-list', $_GET);
    } else {
        $errors = $form->errors();
        minim('user_messaging')->info("Errors in form");
    }
}
minim('templates')->render(array("{$model_name}-edit", 'model-edit'), array('model_name' => $model_name, 'form' => $form, 'errors' => $errors));
Пример #19
0
 function paginate($source)
 {
     $page = $this->page;
     $from = $page - 2;
     if ($from < 1) {
         $from = 1;
     }
     $to = $from + 4;
     if ($to > $this->max_page()) {
         $to = $this->max_page();
         if ($to - 4 > 1) {
             $from = $to - 4;
         } else {
             $from = 1;
         }
     }
     $prev = NULL;
     $next = NULL;
     if ($this->prev_page()) {
         if ($this->prev_page() == 1) {
             $params = $this->url_params;
         } else {
             $params = array_merge($this->url_params, array('page' => $this->prev_page()));
         }
         $prev = minim('routing')->url_for($this->url, $params);
     }
     $url = array();
     for ($i = $from; $i <= $to; $i++) {
         if ($i == 1) {
             $params = $this->url_params;
         } else {
             $params = array_merge($this->url_params, array('page' => $i));
         }
         $url[$i] = minim('routing')->url_for($this->url, $params);
     }
     if ($this->next_page()) {
         $params = array_merge($this->url_params, array('page' => $this->next_page()));
         $next = minim('routing')->url_for($this->url, $params);
     }
     include realpath(dirname(__FILE__)) . "/templates/_pagination.php";
 }
Пример #20
0
      <li><a href="<?php 
echo minim('routing')->url_for('admin-default');
?>
">Dashboard</a></li>
      <li><a href="<?php 
echo minim('routing')->url_for('admin-models');
?>
">Models</a></li>
    </ul>
    <h1><?php 
$this->get('title');
?>
</h1>
    <ul class="messages">
    <?php 
foreach (minim('user_messaging')->get_messages() as $msg) {
    ?>
      <li><?php 
    echo $msg[0];
    ?>
</li>
    <?php 
}
?>
    </ul>
    <?php 
$this->get('page_content');
?>
   </div>
   <div id="footer">
    <p>&copy; 2008 Andy Driver - powered by Minim</p>
Пример #21
0
<?php

error_reporting(E_STRICT | E_ALL);
require_once 'minim/minim.php';
// run all tests
$result = minim('tests')->run_tests(path(dirname(__FILE__), '..'));
minim('tests')->output_results();
exit($result);