示例#1
0
 public function write($str, $type = null)
 {
     $type = is_null($type) ? 'INFO' : $type;
     $type = Inflector::upper($type);
     $data = date('Y-m-d H:i:s') . ":{$type}:{$str}";
     File::append($this->file, $data . "\n");
 }
示例#2
0
文件: Input.php 项目: schpill/thin
 public static function __callStatic($method, $args)
 {
     $auth = ['GET', 'POST', 'COOKIE', 'SESSION', 'SERVER', 'REQUEST', 'GLOBALS'];
     $method = Inflector::upper($method);
     if (Arrays::in($method, $auth) && count($args) > 0) {
         $default = isset($args[1]) ? $args[1] : null;
         return isAke(self::tab($method), Arrays::first($args), $default);
     } elseif (Arrays::in($method, $auth) && count($args) == 0) {
         return self::tab($method);
     } else {
         throw new Exception("Wrong parameters.");
     }
 }
示例#3
0
 public static function ccode($code, $reverse = false)
 {
     $array = array('AF' => 'Afghanistan', 'AX' => 'Aland Islands', 'AL' => 'Albania', 'DZ' => 'Algeria', 'AS' => 'American Samoa', 'AD' => 'Andorra', 'AO' => 'Angola', 'AI' => 'Anguilla', 'AQ' => 'Antarctica', 'AG' => 'Antigua And Barbuda', 'AR' => 'Argentina', 'AM' => 'Armenia', 'AW' => 'Aruba', 'AU' => 'Australia', 'AT' => 'Austria', 'AZ' => 'Azerbaijan', 'BS' => 'Bahamas', 'BH' => 'Bahrain', 'BD' => 'Bangladesh', 'BB' => 'Barbados', 'BY' => 'Belarus', 'BE' => 'Belgium', 'BZ' => 'Belize', 'BJ' => 'Benin', 'BM' => 'Bermuda', 'BT' => 'Bhutan', 'BO' => 'Bolivia', 'BA' => 'Bosnia And Herzegovina', 'BW' => 'Botswana', 'BV' => 'Bouvet Island', 'BR' => 'Brazil', 'IO' => 'British Indian Ocean Territory', 'BN' => 'Brunei Darussalam', 'BG' => 'Bulgaria', 'BF' => 'Burkina Faso', 'BI' => 'Burundi', 'KH' => 'Cambodia', 'CM' => 'Cameroon', 'CA' => 'Canada', 'CV' => 'Cape Verde', 'KY' => 'Cayman Islands', 'CF' => 'Central African Republic', 'TD' => 'Chad', 'CL' => 'Chile', 'CN' => 'China', 'CX' => 'Christmas Island', 'CC' => 'Cocos (Keeling) Islands', 'CO' => 'Colombia', 'KM' => 'Comoros', 'CG' => 'Congo', 'CD' => 'Congo, Democratic Republic', 'CK' => 'Cook Islands', 'CR' => 'Costa Rica', 'CI' => 'Cote D\'Ivoire', 'HR' => 'Croatia', 'CU' => 'Cuba', 'CY' => 'Cyprus', 'CZ' => 'Czech Republic', 'DK' => 'Denmark', 'DJ' => 'Djibouti', 'DM' => 'Dominica', 'DO' => 'Dominican Republic', 'EC' => 'Ecuador', 'EG' => 'Egypt', 'SV' => 'El Salvador', 'GQ' => 'Equatorial Guinea', 'ER' => 'Eritrea', 'EE' => 'Estonia', 'ET' => 'Ethiopia', 'FK' => 'Falkland Islands (Malvinas)', 'FO' => 'Faroe Islands', 'FJ' => 'Fiji', 'FI' => 'Finland', 'FR' => 'France', 'GF' => 'French Guiana', 'PF' => 'French Polynesia', 'TF' => 'French Southern Territories', 'GA' => 'Gabon', 'GM' => 'Gambia', 'GE' => 'Georgia', 'DE' => 'Germany', 'GH' => 'Ghana', 'GI' => 'Gibraltar', 'GR' => 'Greece', 'GL' => 'Greenland', 'GD' => 'Grenada', 'GP' => 'Guadeloupe', 'GU' => 'Guam', 'GT' => 'Guatemala', 'GG' => 'Guernsey', 'GN' => 'Guinea', 'GW' => 'Guinea-Bissau', 'GY' => 'Guyana', 'HT' => 'Haiti', 'HM' => 'Heard Island & Mcdonald Islands', 'VA' => 'Holy See (Vatican City State)', 'HN' => 'Honduras', 'HK' => 'Hong Kong', 'HU' => 'Hungary', 'IS' => 'Iceland', 'IN' => 'India', 'ID' => 'Indonesia', 'IR' => 'Iran, Islamic Republic Of', 'IQ' => 'Iraq', 'IE' => 'Ireland', 'IM' => 'Isle Of Man', 'IL' => 'Israel', 'IT' => 'Italy', 'JM' => 'Jamaica', 'JP' => 'Japan', 'JE' => 'Jersey', 'JO' => 'Jordan', 'KZ' => 'Kazakhstan', 'KE' => 'Kenya', 'KI' => 'Kiribati', 'KR' => 'Korea', 'KW' => 'Kuwait', 'KG' => 'Kyrgyzstan', 'LA' => 'Lao People\'s Democratic Republic', 'LV' => 'Latvia', 'LB' => 'Lebanon', 'LS' => 'Lesotho', 'LR' => 'Liberia', 'LY' => 'Libyan Arab Jamahiriya', 'LI' => 'Liechtenstein', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 'MO' => 'Macao', 'MK' => 'Macedonia', 'MG' => 'Madagascar', 'MW' => 'Malawi', 'MY' => 'Malaysia', 'MV' => 'Maldives', 'ML' => 'Mali', 'MT' => 'Malta', 'MH' => 'Marshall Islands', 'MQ' => 'Martinique', 'MR' => 'Mauritania', 'MU' => 'Mauritius', 'YT' => 'Mayotte', 'MX' => 'Mexico', 'FM' => 'Micronesia, Federated States Of', 'MD' => 'Moldova', 'MC' => 'Monaco', 'MN' => 'Mongolia', 'ME' => 'Montenegro', 'MS' => 'Montserrat', 'MA' => 'Morocco', 'MZ' => 'Mozambique', 'MM' => 'Myanmar', 'NA' => 'Namibia', 'NR' => 'Nauru', 'NP' => 'Nepal', 'NL' => 'Netherlands', 'AN' => 'Netherlands Antilles', 'NC' => 'New Caledonia', 'NZ' => 'New Zealand', 'NI' => 'Nicaragua', 'NE' => 'Niger', 'NG' => 'Nigeria', 'NU' => 'Niue', 'NF' => 'Norfolk Island', 'MP' => 'Northern Mariana Islands', 'NO' => 'Norway', 'OM' => 'Oman', 'PK' => 'Pakistan', 'PW' => 'Palau', 'PS' => 'Palestinian Territory, Occupied', 'PA' => 'Panama', 'PG' => 'Papua New Guinea', 'PY' => 'Paraguay', 'PE' => 'Peru', 'PH' => 'Philippines', 'PN' => 'Pitcairn', 'PL' => 'Poland', 'PT' => 'Portugal', 'PR' => 'Puerto Rico', 'QA' => 'Qatar', 'RE' => 'Reunion', 'RO' => 'Romania', 'RU' => 'Russian Federation', 'RW' => 'Rwanda', 'BL' => 'Saint Barthelemy', 'SH' => 'Saint Helena', 'KN' => 'Saint Kitts And Nevis', 'LC' => 'Saint Lucia', 'MF' => 'Saint Martin', 'PM' => 'Saint Pierre And Miquelon', 'VC' => 'Saint Vincent And Grenadines', 'WS' => 'Samoa', 'SM' => 'San Marino', 'ST' => 'Sao Tome And Principe', 'SA' => 'Saudi Arabia', 'SN' => 'Senegal', 'RS' => 'Serbia', 'SC' => 'Seychelles', 'SL' => 'Sierra Leone', 'SG' => 'Singapore', 'SK' => 'Slovakia', 'SI' => 'Slovenia', 'SB' => 'Solomon Islands', 'SO' => 'Somalia', 'ZA' => 'South Africa', 'GS' => 'South Georgia And Sandwich Isl.', 'ES' => 'Spain', 'LK' => 'Sri Lanka', 'SD' => 'Sudan', 'SR' => 'Suriname', 'SJ' => 'Svalbard And Jan Mayen', 'SZ' => 'Swaziland', 'SE' => 'Sweden', 'CH' => 'Switzerland', 'SY' => 'Syrian Arab Republic', 'TW' => 'Taiwan', 'TJ' => 'Tajikistan', 'TZ' => 'Tanzania', 'TH' => 'Thailand', 'TL' => 'Timor-Leste', 'TG' => 'Togo', 'TK' => 'Tokelau', 'TO' => 'Tonga', 'TT' => 'Trinidad And Tobago', 'TN' => 'Tunisia', 'TR' => 'Turkey', 'TM' => 'Turkmenistan', 'TC' => 'Turks And Caicos Islands', 'TV' => 'Tuvalu', 'UG' => 'Uganda', 'UA' => 'Ukraine', 'AE' => 'United Arab Emirates', 'GB' => 'United Kingdom', 'US' => 'United States', 'UM' => 'United States Outlying Islands', 'UY' => 'Uruguay', 'UZ' => 'Uzbekistan', 'VU' => 'Vanuatu', 'VE' => 'Venezuela', 'VN' => 'Viet Nam', 'VG' => 'Virgin Islands, British', 'VI' => 'Virgin Islands, U.S.', 'WF' => 'Wallis And Futuna', 'EH' => 'Western Sahara', 'YE' => 'Yemen', 'ZM' => 'Zambia', 'ZW' => 'Zimbabwe');
     if ($reverse) {
         $array = array_flip($array);
         if (isset($array[$code])) {
             return $array[$code];
         }
     }
     $code = Inflector::upper($code);
     if (isset($array[$code])) {
         return $array[$code];
     }
 }
示例#4
0
文件: Form.php 项目: noikiy/inovi
 public static function open($action = null, $method = 'POST', $attributes = array(), $https = null, $upload = false)
 {
     $method = Inflector::upper($method);
     if (!Arrays::exists('id', $attributes)) {
         $attributes['id'] = md5(static::action($action, $https));
     }
     $attributes['method'] = static::method($method);
     $attributes['action'] = static::action($action, $https);
     if (true === $upload) {
         $attributes['enctype'] = 'multipart/form-data';
     }
     if (!Arrays::exists('accept-charset', $attributes)) {
         $attributes['accept-charset'] = 'utf-8';
     }
     $append = '';
     if ($method == 'PUT' || $method == 'DELETE') {
         $append = static::hidden(static::spoofer, $method);
     }
     return '<form' . Html::attributes($attributes) . '>' . $append;
 }
示例#5
0
文件: View.php 项目: noikiy/inovi
 public function urlsite($echo = true)
 {
     if (null === static::$urlsite) {
         $protocol = 'http';
         if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
             $protocol = 'https';
         }
         container()->setProtocol($protocol);
         $urlSite = "{$protocol}://" . $_SERVER["SERVER_NAME"] . "/";
         if (strstr($urlSite, '//')) {
             $urlSite = repl('//', '/', $urlSite);
             $urlSite = repl($protocol . ':/', $protocol . '://', $urlSite);
         }
         if (Inflector::upper(substr(PHP_OS, 0, 3)) === 'WIN') {
             $tab = explode('\\', $urlSite);
             $r = '';
             foreach ($tab as $c => $v) {
                 $r .= $v;
             }
             $r = repl('//', '/', $r);
             $r = repl($protocol . ':/', $protocol . '://', $r);
             $urlSite = $r;
         }
         static::$urlsite = $urlSite;
     }
     if (false === $echo) {
         return static::$urlsite;
     } else {
         echo static::$urlsite;
         return;
     }
 }
示例#6
0
setlocale(LC_ALL, Config::get('application.lc.all', 'fr_FR.UTF-8'));
require_once __DIR__ . DS . 'helpers/functions.php';
require_once __DIR__ . DS . 'helpers.php';
require_once __DIR__ . DS . 'facades.php';
if (Arrays::exists('SERVER_NAME', $_SERVER)) {
    $protocol = 'http';
    if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
        $protocol .= 's';
    }
    container()->setProtocol($protocol);
    $urlSite = "{$protocol}://" . $_SERVER["SERVER_NAME"] . "/";
    if (strstr($urlSite, '//')) {
        $urlSite = str_replace('//', '/', $urlSite);
        $urlSite = str_replace($protocol . ':/', $protocol . '://', $urlSite);
    }
    if (Inflector::upper(substr(PHP_OS, 0, 3)) === 'WIN') {
        $tab = explode('\\', $urlSite);
        $r = '';
        foreach ($tab as $c => $v) {
            $r .= $v;
        }
        $r = str_replace('//', '/', $r);
        $r = str_replace($protocol . ':/', $protocol . '://', $r);
        $urlSite = $r;
    }
    $base_uri = substr(str_replace('public/index.php', '', $_SERVER['SCRIPT_NAME']), 1);
    if (substr($_SERVER['REQUEST_URI'], 0, strlen($base_uri) + 1) != '/' . $base_uri) {
        $base_uri = '';
    }
    Config::set('application.base_uri', $base_uri);
    $application = Config::get('application');
示例#7
0
文件: Admin.php 项目: schpill/thin
 public static function query($type, $conditions = '', $offset = 0, $limit = 0, $orderField = null, $order = 'ASC')
 {
     $results = array();
     $resultsAnd = array();
     $resultsOr = array();
     $resultsXor = array();
     $datas = static::getAll($type);
     if (!count($datas)) {
         return null;
     }
     if (strlen($conditions) == 0) {
         $conditionsAnd = array();
         $conditionsOr = array();
         $conditionsXor = array();
         $results = $datas;
     } else {
         $conditionsAnd = explode(' && ', $conditions);
         $conditionsOr = explode(' || ', $conditions);
         $conditionsXor = explode(' XOR ', $conditions);
     }
     if (count($conditionsOr) == count($conditionsAnd)) {
         if (current($conditionsOr) == current($conditionsOr)) {
             $conditionsOr = array();
         }
     }
     if (count($conditionsXor) == count($conditionsAnd)) {
         if (current($conditionsXor) == current($conditionsOr)) {
             $conditionsXor = array();
         }
     }
     if (count($conditionsAnd)) {
         foreach ($conditionsAnd as $condition) {
             foreach ($datas as $tmpObject) {
                 $object = static::getObject($tmpObject);
                 $condition = repl('NOT LIKE', 'NOTLIKE', $condition);
                 $condition = repl('NOT IN', 'NOTIN', $condition);
                 list($field, $op, $value) = explode(' ', $condition, 3);
                 $continue = true;
                 if (null !== $object->{$field}) {
                     $continue = static::analyze($object->{$field}, $op, $value);
                 } else {
                     $continue = false;
                 }
                 if (true === $continue) {
                     array_push($resultsAnd, $object);
                 }
             }
         }
         $results = array_intersect($results, $resultsAnd);
     }
     if (count($conditionsOr)) {
         foreach ($conditionsOr as $condition) {
             foreach ($datas as $tmpObject) {
                 $object = static::getObject($tmpObject);
                 $condition = repl('NOT LIKE', 'NOTLIKE', $condition);
                 $condition = repl('NOT IN', 'NOTIN', $condition);
                 list($field, $op, $value) = explode(' ', $condition, 3);
                 $continue = true;
                 if (null !== $object->{$field}) {
                     $continue = static::analyze($object->{$field}, $op, $value);
                 } else {
                     $continue = false;
                 }
                 if (true === $continue) {
                     array_push($resultsOr, $object);
                 }
             }
         }
         $results = array_merge($results, $resultsOr);
     }
     if (count($conditionsXor)) {
         foreach ($conditionsXor as $condition) {
             foreach ($datas as $tmpObject) {
                 $object = static::getObject($tmpObject);
                 $condition = repl('NOT LIKE', 'NOTLIKE', $condition);
                 $condition = repl('NOT IN', 'NOTIN', $condition);
                 list($field, $op, $value) = explode(' ', $condition, 3);
                 $continue = true;
                 if (null !== $object->{$field}) {
                     $continue = static::analyze($object->{$field}, $op, $value);
                 } else {
                     $continue = false;
                 }
                 if (true === $continue) {
                     array_push($resultsXor, $object);
                 }
             }
         }
         $results = array_merge(array_diff($results, $resultsXor), array_diff($resultsXor, $results));
     }
     if (count($results)) {
         if (0 < $limit) {
             $max = count($results);
             $number = $limit - $offset;
             if ($number > $max) {
                 $offset = $max - $limit;
                 if (0 > $offset) {
                     $offset = 0;
                 }
                 $limit = $max;
             }
             $results = array_slice($results, $offset, $limit);
         }
     }
     if (count($results) && null !== $orderField) {
         $sort = array();
         foreach ($results as $object) {
             $tab = (array) $object;
             foreach ($tab as $key => $value) {
                 $sort[$key][] = $value;
             }
         }
         $asort = array();
         foreach ($sort as $key => $rows) {
             for ($i = 0; $i < count($rows); $i++) {
                 if (!is_array(${$key})) {
                     ${$key} = array();
                 }
                 $asort[$i][$key] = $rows[$i];
                 array_push(${$key}, $rows[$i]);
             }
         }
         if ('ASC' == Inflector::upper($order)) {
             array_multisort(${$orderField}, SORT_ASC, $asort);
         } else {
             array_multisort(${$orderField}, SORT_DESC, $asort);
         }
         $collection = array();
         foreach ($asort as $key => $row) {
             $tmpId = $row['id'];
             $tmpObject = static::getById($type, $tmpId);
             array_push($collection, static::getObject($tmpObject));
         }
         $results = $collection;
     }
     return $results;
 }
示例#8
0
 public function makeVoucher()
 {
     return 'R' . Inflector::upper(Inflector::random(9));
 }
示例#9
0
文件: Log.php 项目: schpill/thin
 protected static function format($type, $message)
 {
     return date('Y-m-d H:i:s') . ' ' . Inflector::upper($type) . " - {$message}" . PHP_EOL;
 }
示例#10
0
文件: Orm.php 项目: schpill/thin
 public function describe()
 {
     $desc = array();
     $q = 'DESCRIBE ' . $this->_dbName . '.' . $this->_tableName;
     $res = $this->_query($q);
     if (is_array($res)) {
         $count = count($res);
     } else {
         $count = $res->rowCount();
     }
     if (0 < $count) {
         $field = 0;
         $type = 1;
         $null = 2;
         $key = 3;
         $default = 4;
         $extra = 5;
         $i = 1;
         $p = 1;
         foreach ($res as $row) {
             list($length, $scale, $precision, $unsigned, $primary, $index, $primaryPosition, $identity) = array(null, null, null, null, false, false, null, false);
             if (preg_match('/unsigned/', $row[$type])) {
                 $unsigned = true;
             }
             if (preg_match('/^((?:var)?char)\\((\\d+)\\)/', $row[$type], $matches)) {
                 $row[$type] = $matches[1];
                 $length = $matches[2];
             } else {
                 if (preg_match('/^decimal\\((\\d+),(\\d+)\\)/', $row[$type], $matches)) {
                     $row[$type] = 'decimal';
                     $precision = $matches[1];
                     $scale = $matches[2];
                 } else {
                     if (preg_match('/^float\\((\\d+),(\\d+)\\)/', $row[$type], $matches)) {
                         $row[$type] = 'float';
                         $precision = $matches[1];
                         $scale = $matches[2];
                     } else {
                         if (preg_match('/^((?:big|medium|small|tiny)?int)\\((\\d+)\\)/', $row[$type], $matches)) {
                             $row[$type] = $matches[1];
                             // The optional argument of a MySQL int type is not precision
                             // or length; it is only a hint for display width.
                         }
                     }
                 }
             }
             if (strlen($row[$key])) {
                 if (Inflector::upper($row[$key]) == 'PRI') {
                     $primary = true;
                     $primaryPosition = $p;
                     if ($row[$extra] == 'auto_increment') {
                         $identity = true;
                         $index = true;
                     } else {
                         $identity = false;
                     }
                     ++$p;
                 } else {
                     $index = true;
                 }
             }
             $desc[$this->foldCase($row[$field])] = array('ENTITY_NAME' => $this->foldCase($this->_dbName), 'TABLE_NAME' => $this->foldCase($this->_tableName), 'COLUMN_NAME' => $this->foldCase($row[$field]), 'COLUMN_POSITION' => $i, 'DATA_TYPE' => $row[$type], 'DEFAULT' => $row[$default], 'NULLABLE' => (bool) ($row[$null] == 'YES'), 'LENGTH' => $length, 'SCALE' => $scale, 'PRECISION' => $precision, 'UNSIGNED' => $unsigned, 'PRIMARY' => $primary, 'PRIMARY_POSITION' => $primaryPosition, 'INDEX' => $index, 'IDENTITY' => $identity);
             ++$i;
         }
     }
     return $desc;
 }
示例#11
0
文件: Redisraw.php 项目: schpill/thin
 /**
  * Build the Redis command based from a given method and parameters.
  *
  * Redis protocol states that a command should conform to the following format:
  *
  *     *<number of arguments> CR LF
  *     $<number of bytes of argument 1> CR LF
  *     <argument data> CR LF
  *     ...
  *     $<number of bytes of argument N> CR LF
  *     <argument data> CR LF
  *
  * More information regarding the Redis protocol: http://redis.io/topics/protocol
  *
  * @param  string  $method
  * @param  array   $parameters
  * @return string
  */
 protected function command($method, $parameters)
 {
     $command = '*' . (count($parameters) + 1) . "\n";
     $command .= '$' . strlen($method) . "\n";
     $command .= Inflector::upper($method) . "\n";
     foreach ($parameters as $parameter) {
         $command .= '$' . strlen($parameter) . "\n" . $parameter . "\n";
     }
     return $command;
 }
示例#12
0
文件: Request.php 项目: schpill/thin
 /**
  * Get an item from the $_SERVER array.
  *
  * @param  string  $key
  * @param  mixed   $default
  * @return string
  */
 public static function server($key = null, $default = null)
 {
     return arrayGet(static::foundation()->server->all(), Inflector::upper($key), $default);
 }
示例#13
0
 public function getVoucherCode()
 {
     return Inflector::upper(Inflector::random(9));
 }
示例#14
0
文件: Info.php 项目: schpill/thin
 function varIsDBResource($var, $db = "mysql")
 {
     if ($db == "pgsql") {
         $db = "pg";
     }
     if ($db == "sybase-db" || $db == "sybase-ct") {
         $db = "sybase";
     }
     $arrFields = array("name", "type", "flags");
     $numrows = call_user_func($db . "_num_rows", $var);
     $numfields = call_user_func($db . "_num_fields", $var);
     $this->makeTableHeader("resource", $db . " result", $numfields + 1);
     echo "<tr><td class=dBug_resourceKey>&nbsp;</td>";
     for ($i = 0; $i < $numfields; $i++) {
         $field_header = "";
         for ($j = 0; $j < count($arrFields); $j++) {
             $db_func = $db . "_field_" . $arrFields[$j];
             if (function_exists($db_func)) {
                 $fheader = call_user_func($db_func, $var, $i) . " ";
                 if ($j == 0) {
                     $field_name = $fheader;
                 } else {
                     $field_header .= $fheader;
                 }
             }
         }
         $field[$i] = call_user_func($db . "_fetch_field", $var, $i);
         echo "<td class=dBug_resourceKey title=\"" . $field_header . "\">" . $field_name . "</td>";
     }
     echo "</tr>";
     for ($i = 0; $i < $numrows; $i++) {
         $row = call_user_func($db . "_fetch_array", $var, constant(Inflector::upper($db) . "_ASSOC"));
         echo "<tr>\n";
         echo "<td class=dBug_resourceKey>" . ($i + 1) . "</td>";
         for ($k = 0; $k < $numfields; $k++) {
             $tempField = $field[$k]->name;
             $fieldrow = $row[$field[$k]->name];
             $fieldrow = $fieldrow == "" ? "[empty string]" : $fieldrow;
             echo "<td>" . $fieldrow . "</td>\n";
         }
         echo "</tr>\n";
     }
     echo "</table>";
     if ($numrows > 0) {
         call_user_func($db . "_data_seek", $var, 0);
     }
 }
示例#15
0
文件: routes.php 项目: noikiy/inovi
<?php

namespace Thin;

$route = route()->setName('home')->setPath('/')->setModule('www')->setController('static')->setAction('home')->assign();
$route = route()->setName('test')->setPath('/(.*)/(.*)/test')->setModule('www')->setController('static')->setAction('test')->setParam1('variable_test')->setSettings1(function ($var) use($route) {
    return Inflector::upper($var);
})->setParam2('super')->setSettings2(function ($var) use($route) {
    return Inflector::upper($var);
})->assign();
/* Backend */
$route = route()->setName('back_home')->setPath('/backend')->setModule('backend')->setController('static')->setAction('home')->assign();
示例#16
0
 public static function order($type, $results, $field = 'date_create', $orderDirection = 'ASC')
 {
     $fields = static::getModel($type);
     $fields['id'] = array();
     $fields['date_create'] = array();
     if (!Arrays::isArray($field)) {
         if (null !== $field && !ake($field, $fields)) {
             $fields[$field] = array();
         }
     } else {
         foreach ($field as $tmpField) {
             if (null !== $tmpField && !ake($tmpField, $fields)) {
                 $fields[$tmpField] = array();
             }
         }
     }
     $sort = array();
     foreach ($results as $object) {
         $path = static::makePath($type, $object);
         $objectCreated = static::getObject($path, $type);
         foreach ($fields as $key => $infos) {
             $value = isset($objectCreated->{$key}) ? $objectCreated->{$key} : null;
             $sort[$key][] = $value;
         }
     }
     $asort = array();
     foreach ($sort as $key => $rows) {
         for ($i = 0; $i < count($rows); $i++) {
             if (empty(${$key}) || is_string(${$key})) {
                 ${$key} = array();
             }
             $asort[$i][$key] = $rows[$i];
             array_push(${$key}, $rows[$i]);
         }
     }
     if (Arrays::isArray($field) && Arrays::isArray($orderDirection)) {
         if (count($field) == 2) {
             $first = current($field);
             $second = end($field);
             if ('ASC' == Inflector::upper(current($orderDirection)) && 'ASC' == Inflector::upper(end($orderDirection))) {
                 array_multisort(${$first}, SORT_ASC, ${$second}, SORT_ASC, $asort);
             } elseif ('DESC' == Inflector::upper(current($orderDirection)) && 'ASC' == Inflector::upper(end($orderDirection))) {
                 array_multisort(${$first}, SORT_DESC, ${$second}, SORT_ASC, $asort);
             } elseif ('DESC' == Inflector::upper(current($orderDirection)) && 'DESC' == Inflector::upper(end($orderDirection))) {
                 array_multisort(${$first}, SORT_DESC, ${$second}, SORT_DESC, $asort);
             } elseif ('ASC' == Inflector::upper(current($orderDirection)) && 'DESC' == Inflector::upper(end($orderDirection))) {
                 array_multisort(${$first}, SORT_ASC, ${$second}, SORT_DESC, $asort);
             }
         }
     } else {
         if ('ASC' == Inflector::upper($orderDirection)) {
             array_multisort(${$field}, SORT_ASC, $asort);
         } else {
             array_multisort(${$field}, SORT_DESC, $asort);
         }
     }
     $collection = array();
     foreach ($asort as $key => $row) {
         $tmpId = $row['id'];
         $tmpObject = static::getById($type, $tmpId);
         array_push($collection, $tmpObject);
     }
     return $collection;
 }
示例#17
0
文件: Jsoneav.php 项目: schpill/thin
 public function order($fieldOrder, $orderDirection = 'ASC', $results = array())
 {
     $res = count($results) ? $results : $this->results;
     if (empty($res)) {
         return $this;
     }
     $keyCache = sha1('eavJS_order_' . serialize($fieldOrder) . serialize($orderDirection) . serialize($res) . $this->entity);
     $cached = $this->cached($keyCache);
     if (empty($cached)) {
         $settings = isAke(self::$configs, $this->entity);
         $_fields = isAke($settings, 'fields');
         $fields = empty($_fields) ? array_keys(Arrays::first($res)) : $_fields;
         $sort = array();
         foreach ($res as $i => $tab) {
             foreach ($fields as $k) {
                 $value = isAke($tab, $k, null);
                 $sort[$k][] = $value;
             }
         }
         $asort = array();
         foreach ($sort as $key => $rows) {
             for ($i = 0; $i < count($rows); $i++) {
                 if (empty(${$key}) || is_string(${$key})) {
                     ${$key} = array();
                 }
                 $asort[$i][$key] = $rows[$i];
                 array_push(${$key}, $rows[$i]);
             }
         }
         if (Arrays::is($fieldOrder) && !Arrays::is($orderDirection)) {
             $t = array();
             foreach ($fieldOrder as $tmpField) {
                 array_push($t, $orderDirection);
             }
             $orderDirection = $t;
         }
         if (Arrays::is($fieldOrder) && Arrays::is($orderDirection)) {
             if (count($orderDirection) < count($fieldOrder)) {
                 throw new Exception('You must provide the same arguments number of fields sorting and directions sorting.');
             }
             if (count($fieldOrder) == 1) {
                 $fieldOrder = Arrays::first($fieldOrder);
                 if ('ASC' == Inflector::upper(Arrays::first($orderDirection))) {
                     array_multisort(${$fieldOrder}, SORT_ASC, $asort);
                 } else {
                     array_multisort(${$fieldOrder}, SORT_DESC, $asort);
                 }
             } elseif (count($fieldOrder) > 1) {
                 $params = array();
                 foreach ($fieldOrder as $k => $tmpField) {
                     $tmpSort = isset($orderDirection[$k]) ? $orderDirection[$k] : 'ASC';
                     $params[] = ${$tmpField};
                     $params[] = 'ASC' == $tmpSort ? SORT_ASC : SORT_DESC;
                 }
                 $params[] = $asort;
                 call_user_func_array('array_multisort', $params);
             }
         } else {
             if ('ASC' == Inflector::upper($orderDirection)) {
                 array_multisort(${$fieldOrder}, SORT_ASC, $asort);
             } else {
                 array_multisort(${$fieldOrder}, SORT_DESC, $asort);
             }
         }
         $collection = array();
         foreach ($asort as $key => $row) {
             array_push($collection, $row);
         }
         $this->cached($keyCache, $collection);
     } else {
         $collection = $cached;
     }
     $this->results = $collection;
     return $this;
 }
示例#18
0
文件: Eavdata.php 项目: schpill/thin
 public static function query($entity, $conditions = '', $offset = 0, $limit = 0, $orderField = null, $orderDirection = 'ASC')
 {
     $dataClass = static::$_dataClass;
     static::_exec('_incQueries', array(static::_exec('_getTime', array())));
     $queryKey = sha1(serialize(func_get_args()));
     if (true === $dataClass::$_buffer) {
         $buffer = static::_exec('_buffer', array($queryKey));
         if (false !== $buffer) {
             return $buffer;
         }
     }
     $results = array();
     $resultsAnd = array();
     $resultsOr = array();
     $resultsXor = array();
     $fields = static::fields($entity);
     if (!Arrays::isArray($orderField)) {
         if (null !== $orderField && !ake($orderField, $fields)) {
             $fields[$orderField] = array();
         }
     } else {
         foreach ($orderField as $tmpField) {
             if (null !== $tmpField && !ake($tmpField, $fields)) {
                 $fields[$tmpField] = array();
             }
         }
     }
     $datas = static::getAll($entity);
     if (!count($datas)) {
         return $results;
     }
     if (!strlen($conditions)) {
         $conditionsAnd = array();
         $conditionsOr = array();
         $conditionsXor = array();
         $results = $datas;
     } else {
         $conditionsAnd = explode(' && ', $conditions);
         $conditionsOr = explode(' || ', $conditions);
         $conditionsXor = explode(' XOR ', $conditions);
     }
     if (count($conditionsOr) == count($conditionsAnd)) {
         if (current($conditionsOr) == current($conditionsAnd)) {
             $conditionsAnd = array();
         }
     }
     if (count($conditionsXor) == count($conditionsOr)) {
         if (current($conditionsXor) == current($conditionsOr)) {
             $conditionsXor = array();
         }
     }
     if (count($conditionsAnd)) {
         foreach ($conditionsAnd as $condition) {
             foreach ($datas as $tmpObject) {
                 $object = static::_exec('getObject', array($tmpObject, 'eavrecord'));
                 if (!is_object($object)) {
                     continue;
                 }
                 $object = $object->getData()->setId($object->getId());
                 $condition = repl('NOT LIKE', 'NOTLIKE', $condition);
                 $condition = repl('NOT IN', 'NOTIN', $condition);
                 list($field, $op, $value) = explode(' ', $condition, 3);
                 $continue = true;
                 if (null !== $object->{$field}) {
                     $continue = static::_exec('analyze', array($object->{$field}, $op, $value));
                 } else {
                     $continue = false;
                 }
                 if (true === $continue) {
                     if (!count($resultsAnd)) {
                         array_push($resultsAnd, $tmpObject);
                     } else {
                         $tmpResult = array($tmpObject);
                         $resultsAnd = array_intersect($resultsAnd, $tmpResult);
                     }
                 }
             }
         }
         if (!count($results)) {
             $results = $resultsAnd;
         } else {
             $results = array_intersect($results, $resultsAnd);
         }
     }
     if (count($conditionsOr)) {
         foreach ($conditionsOr as $condition) {
             foreach ($datas as $tmpObject) {
                 $object = static::_exec('getObject', array($tmpObject, 'eavrecord'));
                 if (!is_object($object)) {
                     continue;
                 }
                 $object = $object->getData()->setId($object->getId());
                 $condition = repl('NOT LIKE', 'NOTLIKE', $condition);
                 $condition = repl('NOT IN', 'NOTIN', $condition);
                 list($field, $op, $value) = explode(' ', $condition, 3);
                 if (!isset($object->{$field})) {
                     $continue = false;
                 } else {
                     if (null !== $object->{$field}) {
                         $continue = static::_exec('analyze', array($object->{$field}, $op, $value));
                     } else {
                         $continue = false;
                     }
                 }
                 if (true === $continue) {
                     if (!count($resultsOr)) {
                         array_push($resultsOr, $tmpObject);
                     } else {
                         $tmpResult = array($tmpObject);
                         $resultsOr = array_merge($resultsOr, $tmpResult);
                     }
                 }
             }
         }
         if (!count($results)) {
             $results = $resultsOr;
         } else {
             $results = array_merge($results, $resultsOr);
         }
     }
     if (count($conditionsXor)) {
         foreach ($conditionsXor as $condition) {
             foreach ($datas as $tmpObject) {
                 $object = static::_exec('getObject', array($tmpObject, 'eavrecord'));
                 if (!is_object($object)) {
                     continue;
                 }
                 $object = $object->getData()->setId($object->getId());
                 $condition = repl('NOT LIKE', 'NOTLIKE', $condition);
                 $condition = repl('NOT IN', 'NOTIN', $condition);
                 list($field, $op, $value) = explode(' ', $condition, 3);
                 $continue = true;
                 if (null !== $object->{$field}) {
                     $continue = static::_exec('analyze', array($object->{$field}, $op, $value));
                 } else {
                     $continue = false;
                 }
                 if (true === $continue) {
                     if (!count($resultsXor)) {
                         array_push($resultsXor, $tmpObject);
                     } else {
                         $tmpResult = array($tmpObject);
                         $resultsXor = array_merge(array_diff($resultsXor, $tmpResult), array_diff($tmpResult, $resultsXor));
                     }
                 }
             }
         }
         if (!count($results)) {
             $results = $resultsXor;
         } else {
             $results = array_merge(array_diff($results, $resultsXor), array_diff($resultsXor, $results));
         }
     }
     if (count($results)) {
         if (0 < $limit) {
             $max = count($results);
             $number = $limit - $offset;
             if ($number > $max) {
                 $offset = $max - $limit;
                 if (0 > $offset) {
                     $offset = 0;
                 }
                 $limit = $max;
             }
             $results = array_slice($results, $offset, $limit);
         }
     }
     if (count($results) && null !== $orderField) {
         if (Arrays::isArray($orderField)) {
             $orderFields = $orderField;
         } else {
             $orderFields = array($orderField);
         }
         foreach ($orderFields as $orderField) {
             $sort = array();
             foreach ($results as $object) {
                 $objectCreated = static::_exec('getObject', array($object, 'eavrecord'));
                 foreach ($fields as $key => $infos) {
                     $value = isset($objectCreated->{$key}) ? $objectCreated->{$key} : null;
                     $sort[$key][] = $value;
                 }
             }
             $asort = array();
             foreach ($sort as $key => $rows) {
                 for ($i = 0; $i < count($rows); $i++) {
                     if (empty(${$key}) || is_string(${$key})) {
                         ${$key} = array();
                     }
                     $asort[$i][$key] = $rows[$i];
                     array_push(${$key}, $rows[$i]);
                 }
             }
             if ('ASC' == Inflector::upper($orderDirection)) {
                 array_multisort(${$orderField}, SORT_ASC, $asort);
             } else {
                 array_multisort(${$orderField}, SORT_DESC, $asort);
             }
             $collection = array();
             foreach ($asort as $key => $row) {
                 $tmpId = $row['id'];
                 $tmpObject = static::getById($tmpId);
                 array_push($collection, $tmpObject);
             }
             $results = $collection;
         }
     }
     if (true === $dataClass::$_buffer) {
         static::_exec('_buffer', array($queryKey, $results));
     }
     return $results;
 }
示例#19
0
 public function getId($model, $name)
 {
     $code = Inflector::upper($model . '_' . str_replace(' ', '_', $name));
     return Model::Status()->firstOrCreate(['code' => $code])->id;
 }
示例#20
0
文件: Phonetic.php 项目: schpill/thin
 public static function french($string)
 {
     $accents = array('É' => 'E', 'È' => 'E', 'Ë' => 'E', 'Ê' => 'E', 'Á' => 'A', 'À' => 'A', 'Ä' => 'A', 'Â' => 'A', 'Å' => 'A', 'Ã' => 'A', 'Æ' => 'E', 'Ï' => 'I', 'Î' => 'I', 'Ì' => 'I', 'Í' => 'I', 'Ô' => 'O', 'Ö' => 'O', 'Ò' => 'O', 'Ó' => 'O', 'Õ' => 'O', 'Ø' => 'O', 'Œ' => 'OEU', 'Ú' => 'U', 'Ù' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ñ' => 'N', 'Ç' => 'S', '¿' => 'E');
     $low2up = array('é' => 'É', 'è' => 'È', 'ë' => 'Ë', 'ê' => 'Ê', 'á' => 'Á', 'â' => 'Â', 'à' => 'À', 'Ä' => 'A', 'Â' => 'A', 'å' => 'Å', 'ã' => 'Ã', 'æ' => 'Æ', 'ï' => 'Ï', 'î' => 'Î', 'ì' => 'Ì', 'í' => 'Í', 'ô' => 'Ô', 'ö' => 'Ö', 'ò' => 'Ò', 'ó' => 'Ó', 'õ' => 'Õ', 'ø' => 'Ø', 'œ' => 'Œ', 'ú' => 'Ú', 'ù' => 'Ù', 'û' => 'Û', 'ü' => 'Ü', 'ç' => 'Ç', 'ñ' => 'Ñ', 'ß' => 'S');
     if (false === Utils::isUtf8($string)) {
         $string = utf8_encode($string);
     }
     $string = strtr($string, $low2up);
     // minuscules accentuées ou composées en majuscules simples
     $string = strtr($string, $accents);
     // majuscules accentuées ou composées en majuscules simples
     $string = Inflector::upper($string);
     // majuscules
     $string = preg_replace('`[^A-Z]`', '', $string);
     // A à Z
     $sBack = $string;
     $string = preg_replace('`O[O]+`', 'OU', $string);
     $string = preg_replace('`SAOU`', 'SOU', $string);
     $string = preg_replace('`OES`', 'OS', $string);
     $string = preg_replace('`CCH`', 'K', $string);
     $string = preg_replace('`CC([IYE])`', 'KS$1', $string);
     $string = preg_replace('`(.)\\1`', '$1', $string);
     // quelques cas particuliers
     if ($string == 'CD') {
         return $string;
     }
     if ($string == 'BD') {
         return $string;
     }
     if ($string == 'BV') {
         return $string;
     }
     if ($string == 'TABAC') {
         return 'TABA';
     }
     if ($string == 'FEU') {
         return 'FE';
     }
     if ($string == 'FE') {
         return $string;
     }
     if ($string == 'FER') {
         return $string;
     }
     if ($string == 'FIEF') {
         return $string;
     }
     if ($string == 'FJORD') {
         return $string;
     }
     if ($string == 'GOAL') {
         return 'GOL';
     }
     if ($string == 'FLEAU') {
         return 'FLEO';
     }
     if ($string == 'HIER') {
         return 'IER';
     }
     if ($string == 'HEU') {
         return 'E';
     }
     if ($string == 'HE') {
         return 'E';
     }
     if ($string == 'OS') {
         return $string;
     }
     if ($string == 'RIZ') {
         return 'RI';
     }
     if ($string == 'RAZ') {
         return 'RA';
     }
     // pré-traitements
     $string = preg_replace('`OIN[GT]$`', 'OIN', $string);
     // terminaisons OING -> OIN
     $string = preg_replace('`E[RS]$`', 'E', $string);
     // supression des terminaisons infinitifs et participes pluriels
     $string = preg_replace('`(C|CH)OEU`', 'KE', $string);
     // pré traitement OEU -> EU
     $string = preg_replace('`MOEU`', 'ME', $string);
     // pré traitement OEU -> EU
     $string = preg_replace('`OE([UI]+)([BCDFGHJKLMNPQRSTVWXZ])`', 'E$1$2', $string);
     // pré traitement OEU OEI -> E
     $string = preg_replace('`^GEN[TS]$`', 'JAN', $string);
     // pré traitement GEN -> JAN
     $string = preg_replace('`CUEI`', 'KEI', $string);
     // pré traitement accueil
     $string = preg_replace('`([^AEIOUYC])AE([BCDFGHJKLMNPQRSTVWXZ])`', '$1E$2', $string);
     // pré traitement AE -> E
     $string = preg_replace('`AE([QS])`', 'E$1', $string);
     // pré traitement AE -> E
     $string = preg_replace('`AIE([BCDFGJKLMNPQRSTVWXZ])`', 'AI$1', $string);
     // pré-traitement AIE(consonne) -> AI
     $string = preg_replace('`ANIEM`', 'ANIM', $string);
     // pré traitement NIEM -> NIM
     $string = preg_replace('`(DRA|TRO|IRO)P$`', '$1', $string);
     // P terminal muet
     $string = preg_replace('`(LOM)B$`', '$1', $string);
     // B terminal muet
     $string = preg_replace('`(RON|POR)C$`', '$1', $string);
     // C terminal muet
     $string = preg_replace('`PECT$`', 'PET', $string);
     // C terminal muet
     $string = preg_replace('`ECUL$`', 'CU', $string);
     // L terminal muet
     $string = preg_replace('`(CHA|CA|E)M(P|PS)$`', '$1N', $string);
     // P ou PS terminal muet
     $string = preg_replace('`(TAN|RAN)G$`', '$1', $string);
     // G terminal muet
     $string = repl('JT', 'JOURNAL', $string);
     // JT devient journal
     $string = preg_replace('`([^VO])ILAG`', '$1IAJ', $string);
     $string = preg_replace('`([^TRH])UIL(AR|E)(.+)`', '$1UI$2$3', $string);
     $string = preg_replace('`([G])UIL([AEO])`', '$1UI$2', $string);
     $string = preg_replace('`([NSPM])AIL([AEO])`', '$1AI$2', $string);
     $convMIn = array("DILAI", "DILON", "DILER", "DILEM", "RILON", "TAILE", "GAILET", "AILAI", "AILAR", "OUILA", "EILAI", "EILAR", "EILER", "EILEM", "REILET", "EILET", "AILOL");
     $convMOut = array("DIAI", "DION", "DIER", "DIEM", "RION", "TAIE", "GAIET", "AIAI", "AIAR", "OUIA", "AIAI", "AIAR", "AIER", "AIEM", "RAIET", "EIET", "AIOL");
     $string = repl($convMIn, $convMOut, $string);
     $string = preg_replace('`([^AEIOUY])(SC|S)IEM([EA])`', '$1$2IAM$3', $string);
     // IEM -> IAM
     $string = preg_replace('`^(SC|S)IEM([EA])`', '$1IAM$2', $string);
     // IEM -> IAM
     $convMIn = array('OMB', 'AMB', 'OMP', 'AMP', 'IMB', 'EMP', 'GEMB', 'EMB', 'UMBL', 'CIEN');
     $convMOut = array('ONB', 'ANB', 'ONP', 'ANP', 'INB', 'ANP', 'JANB', 'ANB', 'INBL', 'SIAN');
     $string = repl($convMIn, $convMOut, $string);
     $string = preg_replace('`^ECHO$`', 'EKO', $string);
     // cas particulier écho
     $string = preg_replace('`^ECEUR`', 'EKEUR', $string);
     // cas particulier écoeuré
     $string = preg_replace('`^CH(OG+|OL+|OR+|EU+|ARIS|M+|IRO|ONDR)`', 'K$1', $string);
     //En début de mot
     $string = preg_replace('`(YN|RI)CH(OG+|OL+|OC+|OP+|OM+|ARIS|M+|IRO|ONDR)`', '$1K$2', $string);
     //Ou devant une consonne
     $string = preg_replace('`CHS`', 'CH', $string);
     $string = preg_replace('`CH(AIQ)`', 'K$1', $string);
     $string = preg_replace('`^ECHO([^UIPY])`', 'EKO$1', $string);
     $string = preg_replace('`ISCH(I|E)`', 'ISK$1', $string);
     $string = preg_replace('`^ICHT`', 'IKT', $string);
     $string = preg_replace('`ORCHID`', 'ORKID', $string);
     $string = preg_replace('`ONCHIO`', 'ONKIO', $string);
     $string = preg_replace('`ACHIA`', 'AKIA', $string);
     // retouche ACHIA -> AKIA
     $string = preg_replace('`([^C])ANICH`', '$1ANIK', $string);
     // ANICH -> ANIK    1/2
     $string = preg_replace('`OMANIK`', 'OMANICH', $string);
     // cas particulier  2/2
     $string = preg_replace('`ACHY([^D])`', 'AKI$1', $string);
     $string = preg_replace('`([AEIOU])C([BDFGJKLMNPQRTVWXZ])`', '$1K$2', $string);
     // voyelle, C, consonne sauf H
     $convPrIn = array('EUCHA', 'YCHIA', 'YCHA', 'YCHO', 'YCHED', 'ACHEO', 'RCHEO', 'RCHES', 'ECHN', 'OCHTO', 'CHORA', 'CHONDR', 'CHORE', 'MACHM', 'BRONCHO', 'LICHOS', 'LICHOC');
     $convPrOut = array('EKA', 'IKIA', 'IKA', 'IKO', 'IKED', 'AKEO', 'RKEO', 'RKES', 'EKN', 'OKTO', 'KORA', 'KONDR', 'KORE', 'MAKM', 'BRONKO', 'LIKOS', 'LIKOC');
     $string = repl($convPrIn, $convPrOut, $string);
     $convPrIn = array('WA', 'WO', 'WI', 'WHI', 'WHY', 'WHA', 'WHO');
     $convPrOut = array('OI', 'O', 'OUI', 'OUI', 'OUI', 'OUA', 'OU');
     $string = repl($convPrIn, $convPrOut, $string);
     $convPrIn = array('GNES', 'GNET', 'GNER', 'GNE', 'GI', 'GNI', 'GNA', 'GNOU', 'GNUR', 'GY', 'OUGAIN', 'AGEOL', 'AGEOT', 'GEOLO', 'GEOM', 'GEOP', 'GEOG', 'GEOS', 'GEORG', 'GEOR', 'NGEOT', 'UGEOT', 'GEOT', 'GEOD', 'GEOC', 'GEO', 'GEA', 'GE', 'QU', 'Q', 'CY', 'CI', 'CN', 'ICM', 'CEAT', 'CE', 'CR', 'CO', 'CUEI', 'CU', 'VENCA', 'CA', 'CS', 'CLEN', 'CL', 'CZ', 'CTIQ', 'CTIF', 'CTIC', 'CTIS', 'CTIL', 'CTIO', 'CTI', 'CTU', 'CTE', 'CTO', 'CTR', 'CT', 'PH', 'TH', 'OW', 'LH', 'RDL', 'CHLO', 'CHR', 'PTIA');
     $convPrOut = array('NIES', 'NIET', 'NIER', 'NE', 'JI', 'NI', 'NIA', 'NIOU', 'NIUR', 'JI', 'OUGIN', 'AJOL', 'AJOT', 'JEOLO', 'JEOM', 'JEOP', 'JEOG', 'JEOS', 'JORJ', 'JEOR', 'NJOT', 'UJOT', 'JEOT', 'JEOD', 'JEOC', 'JO', 'JA', 'JE', 'K', 'K', 'SI', 'SI', 'KN', 'IKM', 'SAT', 'SE', 'KR', 'KO', 'KEI', 'KU', 'VANSA', 'KA', 'KS', 'KLAN', 'KL', 'KZ', 'KTIK', 'KTIF', 'KTIS', 'KTIS', 'KTIL', 'KSIO', 'KTI', 'KTU', 'KTE', 'KTO', 'KTR', 'KT', 'F', 'T', 'OU', 'L', 'RL', 'KLO', 'KR', 'PSIA');
     $string = repl($convPrIn, $convPrOut, $string);
     $string = preg_replace('`GU([^RLMBSTPZN])`', 'G$1', $string);
     $string = preg_replace('`GNO([MLTNRKG])`', 'NIO$1', $string);
     $string = preg_replace('`GNO([MLTNRKG])`', 'NIO$1', $string);
     $convPrIn = array('BUTIE', 'BUTIA', 'BATIA', 'ANTIEL', 'RETION', 'ENTIEL', 'ENTIAL', 'ENTIO', 'ENTIAI', 'UJETION', 'ATIEM', 'PETIEN', 'CETIE', 'OFETIE', 'IPETI', 'LBUTION', 'BLUTION', 'LETION', 'LATION', 'SATIET');
     $convPrOut = array('BUSIE', 'BUSIA', 'BASIA', 'ANSIEL', 'RESION', 'ENSIEL', 'ENSIAL', 'ENSIO', 'ENSIAI', 'UJESION', 'ASIAM', 'PESIEN', 'CESIE', 'OFESIE', 'IPESI', 'LBUSION', 'BLUSION', 'LESION', 'LASION', 'SASIET');
     $string = repl($convPrIn, $convPrOut, $string);
     $string = preg_replace('`(.+)ANTI(AL|O)`', '$1ANSI$2', $string);
     $string = preg_replace('`(.+)INUTI([^V])`', '$1INUSI$2', $string);
     $string = preg_replace('`([^O])UTIEN`', '$1USIEN', $string);
     $string = preg_replace('`([^DE])RATI[E]$`', '$1RASI$2', $string);
     $string = preg_replace('`([^SNEU]|KU|KO|RU|LU|BU|TU|AU)T(IEN|ION)`', '$1S$2', $string);
     $string = preg_replace('`([^CS])H`', '$1', $string);
     // H muet
     $string = repl("ESH", "ES", $string);
     // H muet
     $string = repl("NSH", "NS", $string);
     // H muet
     $string = repl("SH", "CH", $string);
     $convNasIn = array('OMT', 'IMB', 'IMP', 'UMD', 'TIENT', 'RIENT', 'DIENT', 'IEN', 'YMU', 'YMO', 'YMA', 'YME', 'YMI', 'YMN', 'YM', 'AHO', 'FAIM', 'DAIM', 'SAIM', 'EIN', 'AINS');
     $convNasOut = array('ONT', 'INB', 'INP', 'OND', 'TIANT', 'RIANT', 'DIANT', 'IN', 'IMU', 'IMO', 'IMA', 'IME', 'IMI', 'IMN', 'IN', 'AO', 'FIN', 'DIN', 'SIN', 'AIN', 'INS');
     $string = repl($convNasIn, $convNasOut, $string);
     $string = preg_replace('`AIN$`', 'IN', $string);
     $string = preg_replace('`AIN([BTDK])`', 'IN$1', $string);
     $string = preg_replace('`([^O])UND`', '$1IND', $string);
     $string = preg_replace('`([JTVLFMRPSBD])UN([^IAE])`', '$1IN$2', $string);
     $string = preg_replace('`([JTVLFMRPSBD])UN$`', '$1IN', $string);
     $string = preg_replace('`RFUM$`', 'RFIN', $string);
     $string = preg_replace('`LUMB`', 'LINB', $string);
     $string = preg_replace('`([^BCDFGHJKLMNPQRSTVWXZ])EN`', '$1AN', $string);
     $string = preg_replace('`([VTLJMRPDSBFKNG])EN([BRCTDKZSVN])`', '$1AN$2', $string);
     // on bisse pour les 2bles nasales
     $string = preg_replace('`([VTLJMRPDSBFKNG])EN([BRCTDKZSVN])`', '$1AN$2', $string);
     $string = preg_replace('`^EN([BCDFGHJKLNPQRSTVXZ]|CH|IV|ORG|OB|UI|UA|UY)`', 'AN$1', $string);
     $string = preg_replace('`(^[JRVTH])EN([DRTFGSVJMP])`', '$1AN$2', $string);
     $string = preg_replace('`SEN([ST])`', 'SAN$1', $string);
     $string = preg_replace('`^DESENIV`', 'DESANIV', $string);
     $string = preg_replace('`([^M])EN(UI)`', '$1AN$2', $string);
     $string = preg_replace('`(.+[JTVLFMRPSBD])EN([JLFDSTG])`', '$1AN$2', $string);
     $string = preg_replace('`([VSBSTNRLPM])E[IY]([ACDFRJLGZ])`', '$1AI$2', $string);
     $convNasIn = array('EAU', 'EU', 'Y', 'EOI', 'JEA', 'OIEM', 'OUANJ', 'OUA', 'OUENJ');
     $convNasOut = array('O', 'E', 'I', 'OI', 'JA', 'OIM', 'OUENJ', 'OI', 'OUANJ');
     $string = repl($convNasIn, $convNasOut, $string);
     $string = preg_replace('`AU([^E])`', 'O$1', $string);
     $string = preg_replace('`^BENJ`', 'BINJ', $string);
     // BENJ -> BINJ
     $string = preg_replace('`RTIEL`', 'RSIEL', $string);
     // RTIEL -> RSIEL
     $string = preg_replace('`PINK`', 'PONK', $string);
     // PINK -> PONK
     $string = preg_replace('`KIND`', 'KOND', $string);
     // KIND -> KOND
     $string = preg_replace('`KUM(N|P)`', 'KON$1', $string);
     // KUMN KUMP
     $string = preg_replace('`LKOU`', 'LKO', $string);
     // LKOU -> LKO
     $string = preg_replace('`EDBE`', 'EBE', $string);
     // EDBE pied-bœuf
     $string = preg_replace('`ARCM`', 'ARKM', $string);
     // SCH -> CH
     $string = preg_replace('`SCH`', 'CH', $string);
     // SCH -> CH
     $string = preg_replace('`^OINI`', 'ONI', $string);
     // OINI -> ONI
     $string = preg_replace('`([^NDCGRHKO])APT`', '$1AT', $string);
     // APT -> AT
     $string = preg_replace('`([L]|KON)PT`', '$1T', $string);
     // LPT -> LT
     $string = preg_replace('`OTB`', 'OB', $string);
     // OTB -> OB (hautbois)
     $string = preg_replace('`IXA`', 'ISA', $string);
     // IXA -> ISA
     $string = preg_replace('`TG`', 'G', $string);
     // TG -> G
     $string = preg_replace('`^TZ`', 'TS', $string);
     // TZ -> TS
     $string = preg_replace('`PTIE`', 'TIE', $string);
     // PTIE -> TIE
     $string = preg_replace('`GT`', 'T', $string);
     // GT -> T
     $string = repl("ANKIEM", "ANKILEM", $string);
     $string = preg_replace("`(LO|RE)KEMAN`", "\$1KAMAN", $string);
     // KEMAN -> KAMAN
     $string = preg_replace('`NT(B|M)`', 'N$1', $string);
     // TB -> B  TM -> M
     $string = preg_replace('`GSU`', 'SU', $string);
     // GS -> SU
     $string = preg_replace('`ESD`', 'ED', $string);
     // ESD -> ED
     $string = preg_replace('`LESKEL`', 'LEKEL', $string);
     // LESQUEL -> LEKEL
     $string = preg_replace('`CK`', 'K', $string);
     // CK -> K
     // fins de mots
     $string = preg_replace('`USIL$`', 'USI', $string);
     // USIL -> USI
     $string = preg_replace('`X$|[TD]S$|[DS]$`', '', $string);
     // TS DS LS X T D S...  v2.0
     $string = preg_replace('`([^KL]+)T$`', '$1', $string);
     $string = preg_replace('`^[H]`', '', $string);
     // H muet en début de mot
     $sBack2 = $string;
     $string = preg_replace('`TIL$`', 'TI', $string);
     // TIL -> TI
     $string = preg_replace('`LC$`', 'LK', $string);
     // LC -> LK
     $string = preg_replace('`L[E]?[S]?$`', 'L', $string);
     // LE LES -> L
     $string = preg_replace('`(.+)N[E]?[S]?$`', '$1N', $string);
     // NE NES -> N
     $string = preg_replace('`EZ$`', 'E', $string);
     // EZ -> E
     $string = preg_replace('`OIG$`', 'OI', $string);
     // OIG -> OI
     $string = preg_replace('`OUP$`', 'OU', $string);
     // OUP -> OU
     $string = preg_replace('`([^R])OM$`', '$1ON', $string);
     // OM -> ON sauf ROM
     $string = preg_replace('`LOP$`', 'LO', $string);
     // LOP -> LO
     $string = preg_replace('`NTANP$`', 'NTAN', $string);
     // NTANP -> NTAN
     $string = preg_replace('`TUN$`', 'TIN', $string);
     // TUN -> TIN
     $string = preg_replace('`AU$`', 'O', $string);
     // AU -> O
     $string = preg_replace('`EI$`', 'AI', $string);
     // EI -> AI
     $string = preg_replace('`R[DG]$`', 'R', $string);
     // RD RG -> R
     $string = preg_replace('`ANC$`', 'AN', $string);
     // ANC -> AN
     $string = preg_replace('`KROC$`', 'KRO', $string);
     // C muet de CROC, ESCROC
     $string = preg_replace('`HOUC$`', 'HOU', $string);
     // C muet de CAOUTCHOUC
     $string = preg_replace('`OMAC$`', 'OMA', $string);
     // C muet de ESTOMAC (mais pas HAMAC)
     $string = preg_replace('`([J])O([NU])[CG]$`', '$1O$2', $string);
     // C et G muet de OUC ONC OUG
     $string = preg_replace('`([^GTR])([AO])NG$`', '$1$2N', $string);
     // G muet ANG ONG sauf GANG GONG TANG TONG
     $string = preg_replace('`UC$`', 'UK', $string);
     // UC -> UK
     $string = preg_replace('`AING$`', 'IN', $string);
     // AING -> IN
     $string = preg_replace('`([EISOARN])C$`', '$1K', $string);
     // C -> K
     $string = preg_replace('`([ABD-MO-Z]+)[EH]+$`', '$1', $string);
     // E ou H
     $string = preg_replace('`EN$`', 'AN', $string);
     // EN -> AN
     $string = preg_replace('`(NJ)EN$`', '$1AN', $string);
     // EN -> AN
     $string = preg_replace('`^PAIEM`', 'PAIM', $string);
     // PAIE -> PAI
     $string = preg_replace('`([^NTB])EF$`', '\\1', $string);
     // F muet
     $string = preg_replace('`(.)\\1`', '$1', $string);
     /* part cases */
     $convPartIn = array('FUEL');
     $convPartOut = array('FIOUL');
     $string = repl($convPartIn, $convPartOut, $string);
     if ($string == 'O') {
         return $string;
     }
     if ($string == 'C') {
         return 'SE';
     }
     if (strlen($string) < 2) {
         // acronymes
         if (preg_match("`[BCDFGHJKLMNPQRSTVWXYZ][BCDFGHJKLMNPQRSTVWXYZ][BCDFGHJKLMNPQRSTVWXYZ][BCDFGHJKLMNPQRSTVWXYZ]*`", $sBack)) {
             return $sBack;
         }
         if (preg_match("`[RFMLVSPJDF][AEIOU]`", $sBack)) {
             if (strlen($sBack) == 3) {
                 return substr($sBack, 0, 2);
                 // mots de 3 lettres
             }
             if (strlen($sBack) == 4) {
                 return substr($sBack, 0, 3);
             }
             // mots de 4 lettres
         }
         if (strlen($sBack2) > 1) {
             return $sBack2;
         }
     }
     if (strlen($string) > 1) {
         return substr($string, 0, 32);
     } else {
         return '';
     }
 }
示例#21
0
文件: Mobile.php 项目: schpill/thin
 /**
  * Retrieves a particular header. If it doesn't exist, no exception/error is caused.
  * Simply null is returned.
  *
  * @param string $header The name of the header to retrieve. Can be HTTP compliant such as
  *                       "User-Agent" or "X-Device-User-Agent" or can be php-esque with the
  *                       all-caps, HTTP_ prefixed, underscore seperated awesomeness.
  *
  * @return string|null The value of the header.
  */
 public function getHttpHeader($header)
 {
     //are we using PHP-flavored headers?
     if (strpos($header, '_') === false) {
         $header = repl('-', '_', $header);
         $header = Inflector::upper($header);
     }
     //test the alternate, too
     $altHeader = 'HTTP_' . $header;
     //Test both the regular and the HTTP_ prefix
     if (isset($this->httpHeaders[$header])) {
         return $this->httpHeaders[$header];
     } elseif (isset($this->httpHeaders[$altHeader])) {
         return $this->httpHeaders[$altHeader];
     }
 }
示例#22
0
 public function order($fieldOrder = 'date_create', $orderDirection = 'ASC', $results = array())
 {
     $res = count($results) ? $results : $this->currrentRes();
     if (empty($res)) {
         return $this;
     }
     $data = $this->makeData($res);
     $fields = array_keys(Arrays::first($data)->assoc());
     $sort = array();
     foreach ($data as $objectCreated) {
         foreach ($fields as $key) {
             $value = isset($objectCreated->{$key}) ? $objectCreated->{$key} : null;
             $sort[$key][] = $value;
         }
     }
     $asort = array();
     foreach ($sort as $key => $rows) {
         for ($i = 0; $i < count($rows); $i++) {
             if (empty(${$key}) || is_string(${$key})) {
                 ${$key} = array();
             }
             $asort[$i][$key] = $rows[$i];
             array_push(${$key}, $rows[$i]);
         }
     }
     if (Arrays::is($fieldOrder) && !Arrays::is($orderDirection)) {
         $t = array();
         foreach ($fieldOrder as $tmpField) {
             array_push($t, $orderDirection);
         }
         $orderDirection = $t;
     }
     if (Arrays::is($fieldOrder) && Arrays::is($orderDirection)) {
         if (count($orderDirection) < count($fieldOrder)) {
             throw new Exception('You must provide the same arguments number of fields sorting and directions sorting.');
         }
         if (count($fieldOrder) == 1) {
             $fieldOrder = Arrays::first($fieldOrder);
             if ('ASC' == Inflector::upper(Arrays::first($orderDirection))) {
                 array_multisort(${$fieldOrder}, SORT_ASC, $asort);
             } else {
                 array_multisort(${$fieldOrder}, SORT_DESC, $asort);
             }
         } elseif (count($fieldOrder) > 1) {
             $params = array();
             foreach ($fieldOrder as $k => $tmpField) {
                 $tmpSort = isset($orderDirection[$k]) ? $orderDirection[$k] : 'ASC';
                 $params[] = ${$tmpField};
                 $params[] = 'ASC' == $tmpSort ? SORT_ASC : SORT_DESC;
             }
             $params[] = $asort;
             call_user_func_array('array_multisort', $params);
         }
     } else {
         if ('ASC' == Inflector::upper($orderDirection)) {
             array_multisort(${$fieldOrder}, SORT_ASC, $asort);
         } else {
             array_multisort(${$fieldOrder}, SORT_DESC, $asort);
         }
     }
     $collection = array();
     foreach ($asort as $key => $row) {
         $tmpId = $row['id'];
         array_push($collection, $tmpId);
     }
     $this->results = $collection;
     return $this;
 }
示例#23
0
文件: Txtdata.php 项目: schpill/thin
 private function parseQuery($query)
 {
     $groupBy = array();
     $orderBy = array();
     $orderDir = array();
     $wheres = array();
     $limit = 0;
     $offset = 0;
     $query = preg_replace('/\\s+/u', ' ', $query);
     $query = preg_replace('/[\\)`\\s]from[\\(`\\s]/ui', ' FROM ', $query);
     if (preg_match('/(limit([0-9\\s\\,]+)){1}$/ui', $query, $matches)) {
         $query = str_ireplace(Arrays::first($matches), '', $query);
         $tmp = explode(',', $matches[2]);
         if (isset($tmp[1])) {
             $offset = (int) trim(Arrays::first($tmp));
             $limit = (int) trim($tmp[1]);
         } else {
             $offset = 0;
             $limit = (int) trim(Arrays::first($tmp));
         }
     }
     if (preg_match('/(order\\sby([^\\(\\)]+)){1}$/ui', $query, $matches)) {
         $query = str_ireplace(Arrays::first($matches), '', $query);
         $tmp = explode(',', $matches[2]);
         foreach ($tmp as $item) {
             $item = trim($item);
             $direct = mb_strripos($item, ' desc') == mb_strlen($item) - 5 || mb_strripos($item, '`desc') == mb_strlen($item) - 5 ? 'desc' : 'asc';
             $item = str_ireplace(array(' asc', ' desc', '`asc', '`desc', '`'), '', $item);
             $orderBy[] = $item;
             $orderDir[] = Inflector::upper($direct);
         }
     }
     if (preg_match('/(group\\sby([^\\(\\)]+)){1}$/ui', $query, $matches)) {
         $query = str_ireplace(Arrays::first($matches), '', $query);
         $tmp = explode(',', $matches[2]);
         foreach ($tmp as $item) {
             $item = trim($item);
             $groupBy[] = $item;
         }
     }
     $tmp = preg_replace_callback('/\\( (?> [^)(]+ | (?R) )+ \\)/xui', array($this, 'queryParamsCallback'), $query);
     $words = explode(' ', $query);
     $method = Inflector::lower(Arrays::first($words));
     $parts = explode(' where ', Inflector::lower($query));
     if (2 == count($parts)) {
         $whs = Arrays::last($parts);
         $whs = str_replace(array(' and ', ' or ', ' xor ', ' && ', ' || ', ' | '), array(' AND ', ' OR ', ' XOR ', ' AND ', ' OR ', ' XOR '), $whs);
         $wheres['AND'] = strstr($whs, ' AND ') ? explode(' AND ', $whs) : array();
         $wheres['OR'] = strstr($whs, ' OR ') ? explode(' OR ', $whs) : array();
         $wheres['XOR'] = strstr($whs, ' XOR ') ? explode(' XOR ', $whs) : array();
     }
     return array('method' => $method, 'wheres' => $wheres, 'groupBy' => $groupBy, 'orderBy' => $orderBy, 'orderDir' => $orderDir, 'limit' => $limit, 'offset' => $offset);
 }
示例#24
0
文件: Query.php 项目: schpill/thin
 private function results($joined, $object)
 {
     if (false === $joined) {
         $fields = $this->db->database . "." . $this->db->table . ".*";
         $query = "SELECT {$fields} FROM " . $this->db->database . "." . $this->db->table . " WHERE ";
     } else {
         $fields = '';
         $dbFields = $this->db->map['fields'];
         foreach ($dbFields as $tmpField => $tmpInfos) {
             $fields .= $this->db->database . "." . $this->db->table . "." . $tmpField . " AS " . $tmpField . ", ";
         }
         $fields = substr($fields, 0, -2);
         $query = "SELECT {$fields} FROM " . $this->db->database . "." . $this->db->table;
         foreach ($this->joins as $join) {
             list($db, $fieldOriginal, $fieldTarget, $type) = $join;
             $query .= "\n" . Inflector::upper($type) . ' ' . $db->database . '.' . $db->table . ' ON ' . $fieldTarget . ' = ' . $fieldOriginal;
         }
         $query .= "\n" . 'WHERE ';
     }
     if (count($this->db->wheres)) {
         $first = true;
         foreach ($this->db->wheres as $where) {
             list($op, $condition) = $where;
             if (false === $first) {
                 $query .= " {$op} {$condition}";
             } else {
                 $query .= $condition;
             }
             $first = false;
         }
     } else {
         $query .= '1 = 1';
     }
     if (count($this->db->groupBys)) {
         $query .= ' GROUP BY ';
         $first = true;
         foreach ($this->db->groupBys as $groupBy) {
             if (false === $first) {
                 $query .= ", {$this->database}.{$this->table}.{$groupBy}";
             } else {
                 $query .= $groupBy;
             }
             $first = false;
         }
     }
     if (count($this->db->orders)) {
         $query .= ' ORDER BY ';
         $first = true;
         foreach ($this->db->orders as $order) {
             list($field, $direction) = $order;
             if (false === $first) {
                 $query .= ", {$this->database}.{$this->table}.{$field} {$direction}";
             } else {
                 $query .= "{$this->database}.{$this->table}.{$field} {$direction}";
             }
             $first = false;
         }
     }
     if (isset($this->db->limit)) {
         $offset = isset($this->db->offset) ? $this->db->offset : 0;
         $query .= ' LIMIT ' . $offset . ', ' . $this->db->limit;
     }
     $this->db->query = $query;
     $results = $this->db->fetch($query);
     $collection = $this->db->exec($object, $results);
     if (true === $joined && count($collection)) {
         return $this->related($collection, $object);
     }
     return $collection;
 }