예제 #1
0
<?php

test('Story', 'story', AppInflector::classify('story', 'model'));
test('Story', 'stories', AppInflector::classify('stories', 'model'));
test('ManualChaptersController', 'manual_chapter', AppInflector::classify('manual_chapter', 'controller'));
test('ManualChaptersController', 'Manual_Chapters', AppInflector::classify('Manual_Chapters', 'controller'));
test('ManualChaptersController', 'ManualChapter', AppInflector::classify('ManualChapter', 'controller'));
test('SalesPeopleController', 'sales_person', AppInflector::classify('sales_person', 'controller'));
test('SalesPeopleController', 'sales_people', AppInflector::classify('sales_people', 'controller'));
test('SalesPerson', 'sales_person', AppInflector::classify('sales_person', 'model'));
test('SalesPerson', 'SalesPeople', AppInflector::classify('SalesPeople', 'model'));
test('SalesPerson', 'SalesPeople', Inflector::classify('SalesPeople'));
test('SalesPerson', 'Sales People', Inflector::classify('Sales People'));
test('Sales People', 'Sales Person', Inflector::pluralize('Sales Person'));
test('SalesPerson', 'Sales People', Inflector::classify('Sales People'));
function test($intended, $input, $result)
{
    echo "<pre class=\"test " . ($result == $intended ? 'success' : 'failure') . "\">{$input} -> {$result} ({$intended})</pre>";
}
?>
<style type="text/css" media="screen">
  pre.test {
    margin: 10px 0;
    padding: 10px;
  }
  pre.success {
    background-color: #080;
    color: #8f8;
  }
  pre.failure {
    background-color: #800;
예제 #2
0
 static function Parse($url)
 {
     // save 'original'
     Url::$data['_url'] = $url;
     // send through routes
     Url::$data['url'] = Url::DoRoutes($url);
     // get extension
     preg_match('/(.*)\\.(\\w{1,4})$/Ui', Url::$data['url'], $matches);
     if (!empty($matches)) {
         Url::$data['url'] = $matches[1];
         Url::$data['type'] = $matches[2];
     }
     // get parts
     $parts = explode(DS, Url::$data['url']);
     // is subdomain?
     // if (count($host_parts=explode('.', $_SERVER['HTTP_HOST'])) > 2 && $host_parts[0]!='www') {
     if (($subdomain = Url::GetSubdomain()) != null) {
         Url::$data['is_subdomain'] = true;
         Url::$data['subdomain'] = $subdomain;
     }
     Url::$data['host'] = 'http' . (array_get($_SERVER, 'HTTPS') ? 's' : '') . '://' . wrap($subdomain, '', '.') . DOMAIN;
     // d($url);d_arr($parts);d_arr(Url::$data);die;
     // nothing left?
     if (array_empty($parts)) {
         if (Url::GetData('is_admin')) {
             // is admin
             $parts = array(ADMIN_DEFAULT_CONTROLLER, ADMIN_DEFAULT_ACTION);
         } else {
             // is default
             $parts = explode(DS, Url::GetData('is_subdomain') ? SUBDOMAIN_DEFAULT_URL : DEFAULT_URL);
         }
     }
     // is execute?
     if (Url::$data['type'] == 'php') {
         Url::$data['model'] = 'app';
         Url::$data['modelName'] = 'AppModel';
         Url::$data['controller'] = EXECUTE_CONTROLLER;
         Url::$data['controllerName'] = ucfirst(EXECUTE_CONTROLLER) . 'Controller';
         Url::$data['action'] = 'include_to_buffer';
         // set filename
         Url::$data['params'] = array('filename' => implode(DS, $parts) . '.php');
     } else {
         // set controller
         Url::$data['controller'] = array_shift($parts);
         Url::$data['controllerName'] = AppInflector::classify(Url::$data['controller'], 'controller');
         // set model
         Url::$data['model'] = AppInflector::singularize(Url::$data['controller']);
         Url::$data['modelName'] = AppInflector::classify(Url::$data['model'], 'model');
         // set action
         Url::$data['action'] = ($action = array_shift($parts)) != null ? $action : 'index';
         // add prefix to admin actions
         if (Url::GetData('is_admin')) {
             Url::$data['action'] = ADMIN_PREFIX . Url::$data['action'];
         }
         // set params
         while (($value = array_shift($parts)) != null) {
             Url::$data['params'][] = $value;
         }
     }
     // set request
     Url::$data['request'] = $_REQUEST;
     // set domain
     Url::$data['domain'] = DOMAIN;
     // d_arr(Url::$data);die;
 }
예제 #3
0
 static function Init($name, $type = 'class', $show_errors = true)
 {
     if (self::Load($name, $type, $show_errors)) {
         $class_name = AppInflector::classify($name, $type);
         return $type == 'model' ? AppModel::Create($class_name) : new $class_name();
     } else {
         return new stdClass();
     }
 }