示例#1
0
文件: Db.php 项目: schpill/thin
 public static function connexion()
 {
     $args = func_get_args();
     $class = '\\Thin\\Db\\' . ucfirst(Inflector::lower(Arrays::first($args)));
     array_shift($args);
     return call_user_func_array([$class, 'instance'], $args);
 }
示例#2
0
    public static function instance($model, $db = null, $options = [])
    {
        $db = is_null($db) ? SITE_NAME : $db;
        $class = __NAMESPACE__ . '\\Model\\' . ucfirst(Inflector::lower($model));
        $file = APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . ucfirst(Inflector::lower($db)) . DS . ucfirst(Inflector::lower($model)) . '.php';
        if (File::exists($file)) {
            require_once $file;
            return new $class();
        }
        if (!class_exists($class)) {
            $code = 'namespace ' . __NAMESPACE__ . '\\Model;' . "\n" . '
    class ' . ucfirst(Inflector::lower($model)) . ' extends \\Thin\\MyOrm
    {
        public $timestamps = false;
        protected $table = "' . Inflector::lower($model) . '";

        public static function boot()
        {
            static::unguard();
        }
    }';
            if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql')) {
                $dir = APPLICATION_PATH . DS . 'models' . DS . 'Mysql';
                File::mkdir($dir);
            }
            if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . ucfirst(Inflector::lower($db)))) {
                $dir = APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . ucfirst(Inflector::lower($db));
                File::mkdir($dir);
            }
            File::put($file, '<?php' . "\n" . $code);
            require_once $file;
            return new $class();
        }
    }
示例#3
0
 public function __call($func, $argv)
 {
     if (substr($func, 0, 3) == 'get') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         if (isset($argv[0])) {
             $environment = $argv[0];
         } else {
             $environment = APPLICATION_ENV;
         }
         return getConfig($key, $environment);
     } elseif (substr($func, 0, 3) == 'set') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         $value = Arrays::first($argv);
         if (isset($argv[1])) {
             $environment = $argv[1];
         } else {
             $environment = 'all';
         }
         setConfig($key, $value, $environment);
         return $this;
     } elseif (substr($func, 0, 3) == 'has') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         if (isset($argv[0])) {
             $environment = $argv[0];
         } else {
             $environment = APPLICATION_ENV;
         }
         return null !== getConfig($key, $environment);
     }
 }
示例#4
0
 public function __call($m, $a)
 {
     if (fnmatch('set*', $m)) {
         $k = Inflector::lower(Inflector::uncamelize(lcfirst(substr($m, 3))));
         $v = empty($a) ? true : current($a);
         self::$__events[$this->__ns][$k] = $v;
         return $this;
     } elseif (fnmatch('get*', $m)) {
         $k = Inflector::lower(Inflector::uncamelize(lcfirst(substr($m, 3))));
         if (isset(self::$__events[$this->__ns][$k])) {
             return self::$__events[$this->__ns][$k];
         }
         $default = empty($a) ? null : current($args);
         return $default;
     } elseif (fnmatch('has*', $m)) {
         $k = Inflector::lower(Inflector::uncamelize(lcfirst(substr($m, 3))));
         return isset(self::$__events[$this->__ns][$k]);
     } elseif (fnmatch('clear*', $m)) {
         $k = Inflector::lower(Inflector::uncamelize(lcfirst(substr($m, 5))));
         unset(self::$__events[$this->__ns][$k]);
         return $this;
     } else {
         if (isset(self::$__events[$this->__ns][$m])) {
             $v = self::$__events[$this->__ns][$m];
             if (is_callable($v)) {
                 return call_user_func_array($v, $a);
             } else {
                 return $v;
             }
         }
     }
 }
示例#5
0
文件: Html.php 项目: schpill/thin
 public static function tag($tag, $value = '', $attributes = array())
 {
     $tag = Inflector::lower($tag);
     if ($tag == 'meta') {
         return '<' . $tag . static::attributes($attributes) . ' />';
     }
     return '<' . $tag . static::attributes($attributes) . '>' . static::entities($value) . '</' . $tag . '>';
 }
示例#6
0
 public function boot($cb404 = null)
 {
     if (is_null($cb404)) {
         $this->cb404 = function () {
             return ['static', 'is404', true];
         };
     } else {
         $this->cb404 = $cb404;
     }
     list($controllerName, $action, $render) = $this->init();
     Now::set('request.controller', $controllerName);
     Now::set('request.action', $action);
     $controllerFile = path('module') . DS . 'controllers' . DS . $controllerName . '.php';
     if (!is_file($controllerFile)) {
         $controllerFile = path('module') . DS . 'controllers' . DS . 'static.php';
         $action = 'is404';
     }
     if (!is_file($controllerFile)) {
         if (isset($this->cb404) && is_callable($this->cb404)) {
             Now::set('page404', true);
             return call_user_func($this->cb404);
         } else {
             header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
             die;
         }
     }
     require_once $controllerFile;
     $class = '\\Thin\\' . ucfirst(Inflector::lower($controllerName)) . 'Controller';
     $actions = get_class_methods($class);
     $father = get_parent_class($class);
     if ($father == 'Thin\\FrontController') {
         $a = $action;
         $method = $this->getMethod();
         $action = Inflector::lower($method) . ucfirst(Inflector::camelize(strtolower($action)));
         $controller = new $class();
         $controller->_name = $controllerName;
         $controller->action = $a;
         if (in_array('boot', $actions)) {
             $controller->boot();
         }
         if (in_array($action, $actions)) {
             $controller->{$action}();
         } else {
             Clipp::is404();
         }
         if (in_array('unboot', $actions)) {
             $controller->unboot();
         }
     } else {
         $controller = new $class($action);
     }
     if (true === $render) {
         $this->render($controller, Now::get('page404', false));
     }
 }
示例#7
0
文件: Utils.php 项目: schpill/thin
 public static function __callstatic($method, $args)
 {
     if (substr($method, 0, 3) == 'get') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3)));
         $var = Inflector::lower($uncamelizeMethod);
         $return = static::get($var);
         return $return;
     } elseif (substr($method, 0, 3) == 'set') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3)));
         $var = Inflector::lower($uncamelizeMethod);
         $value = current($args);
         return static::set($var, $value);
     }
 }
示例#8
0
文件: Hmvc.php 项目: schpill/thin
 public static function execute($module, $controller, $action, $args = [])
 {
     $dirModule = APPLICATION_PATH . DS . 'modules' . DS . SITE_NAME . DS . Inflector::lower($module);
     if (!is_dir($dirModule)) {
         throw new Exception("The directory '{$dirModule}' does not exist.");
     }
     $dirController = $dirModule . DS . 'controllers';
     if (!is_dir($dirController)) {
         throw new Exception("The directory '{$dirController}' does not exist.");
     }
     $controllerFile = $dirController . DS . Inflector::lower($controller) . 'Controller.php';
     if (!File::exists($controllerFile)) {
         throw new Exception("The file '{$controllerFile}' does not exist.");
     }
     require_once $controllerFile;
     $oldRoute = container()->getRoute();
     container()->setRoute(with(new Container())->setModule($module)->setController($controller)->setAction($action));
     $controllerClass = 'Thin\\' . Inflector::lower($controller) . 'Controller';
     $controllerInstance = new $controllerClass();
     $actions = get_class_methods($controllerClass);
     if (strstr($action, '-')) {
         $words = explode('-', $action);
         $newAction = '';
         for ($i = 0; $i < count($words); $i++) {
             $word = trim($words[$i]);
             if ($i > 0) {
                 $word = ucfirst($word);
             }
             $newAction .= $word;
         }
         $action = $newAction;
     }
     $actionName = $action . 'Action';
     if (!Arrays::in($actionName, $actions)) {
         throw new Exception("The action '{$actionName}' does not exist in {$controllerFile}.");
     }
     if (Arrays::in('init', $actions)) {
         $controllerInstance->init();
     }
     if (Arrays::in('preDispatch', $actions)) {
         $controllerInstance->preDispatch();
     }
     $res = call_user_func_array([$controllerInstance, $actionName], $args);
     if (Arrays::in('postDispatch', $actions)) {
         $controllerInstance->preDispatch();
     }
     container()->setRoute($oldRoute);
     return $res;
 }
示例#9
0
文件: Route.php 项目: schpill/thin
 public static function assetBundle($path = 'css/style.css')
 {
     $route = Utils::get('appDispatch');
     $bundle = $route->getBundle();
     if (!is_null($bundle)) {
         $bpath = realpath(APPLICATION_PATH . '/../');
         $bundle = ucfirst(Inflector::lower($bundle));
         $assetsDir = $bpath . DS . 'bundles' . DS . $bundle . DS . 'public';
         $file = $assetsDir . DS . $path;
         if (File::exists($file)) {
             $url = URLSITE . 'bundles/' . $bundle . '/public/' . $path;
         }
     }
     return URLSITE . '/' . $path;
 }
示例#10
0
文件: Info.php 项目: schpill/thin
 function __construct($var, $forceType = "", $bCollapsed = false)
 {
     //include js and css scripts
     if (!defined('THINDBINIT')) {
         define('THINDBINIT', true);
         $this->initJSandCSS();
     }
     $arrAccept = array("array", "object", "xml");
     //array of variable types that can be "forced"
     $this->bCollapsed = $bCollapsed;
     if (Arrays::inArray($forceType, $arrAccept)) {
         $this->{"varIs" . ucfirst(Inflector::lower($forceType))}($var);
     } else {
         $this->checkType($var);
     }
 }
示例#11
0
文件: Metadata.php 项目: schpill/thin
 public function __call($func, $argv)
 {
     if (substr($func, 0, 3) == 'get') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         return getMeta($key);
     } elseif (substr($func, 0, 3) == 'set') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         $value = Arrays::first($argv);
         setMeta($key, $value);
         return $this;
     } elseif (substr($func, 0, 3) == 'has') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         return null !== getMeta($key);
     }
 }
示例#12
0
 public function dispatch($uri)
 {
     if (fnmatch('*/*/*', $uri) && !fnmatch('*/*/*/*', $uri)) {
         list($token, $controller, $action) = explode('/', $uri);
         if (strstr($action, '?')) {
             list($action, $query) = explode('?', $action, 2);
             $query = urldecode($query);
             parse_str($query, $query);
             foreach ($query as $k => $v) {
                 $_REQUEST[$k] = $v;
             }
         }
         $controller = Inflector::lower($controller);
         $action = Inflector::lower($action);
         $dir = Config::get('webservices.dir', APPLICATION_PATH . DS . 'webservices');
         if (is_dir($dir)) {
             $acl = $dir . DS . 'acl.php';
             if (is_file($acl)) {
                 $acl = (include $acl);
                 $userrights = isAke($acl, $token, []);
                 $controllerRights = isAke($userrights, $controller, []);
                 if (in_array($action, $controllerRights)) {
                     $file = $dir . DS . $controller . '.php';
                     if (is_file($file)) {
                         require_once $file;
                         $class = 'Thin\\' . Inflector::camelize($controller . '_webservice');
                         $instance = lib('caller')->make($class);
                         $methods = get_class_methods($instance);
                         if (in_array('init', $methods)) {
                             $instance->init();
                         }
                         if (in_array('boot', $methods)) {
                             $instance->boot();
                         }
                         if (in_array($action, $methods)) {
                             return $instance->{$action}();
                         }
                     }
                 }
             }
         }
     }
     Api::forbidden();
 }
示例#13
0
 public function boot()
 {
     $uri = $this->getUri();
     list($controllerName, $action, $render) = $this->routes($uri);
     RouterLib::$data['controller'] = $controllerName;
     RouterLib::$data['action'] = $action;
     $controllerFile = Config::get('app.module.dir') . DS . 'controllers' . DS . $controllerName . '.php';
     if (!is_file($controllerFile)) {
         $controllerFile = Config::get('app.module.dir') . DS . 'controllers' . DS . 'static.php';
         $action = 404;
     }
     require_once $controllerFile;
     $class = '\\Thin\\' . ucfirst(Inflector::lower(SITE_NAME)) . ucfirst(Inflector::lower($controllerName)) . 'Controller';
     RouterLib::$request = (new Object())->populate($_REQUEST);
     $controller = new $class($action);
     if (true === $render) {
         self::render($controller);
     }
 }
示例#14
0
文件: Provider.php 项目: schpill/thin
 public function factory()
 {
     if (File::exists($this->file)) {
         require_once $this->file;
         $instance = new $this->class();
         $methods = get_class_methods($this->class);
         $tab = explode('\\', get_class($instance));
         $item = Inflector::lower(Arrays::last($tab));
         if (Arrays::in('init', $methods)) {
             $instance->init();
         }
         $this->app->bindShared($this->type . '.' . $item, function ($app) use($instance) {
             return $instance;
         });
         return $this;
     } else {
         throw new Exception("The file '{$file}' does not exist.");
     }
 }
示例#15
0
 public function boot()
 {
     $uri = $this->getUri();
     list($controllerName, $action, $render) = $this->routes($uri);
     Now::set('controller', $controllerName);
     Now::set('action', $action);
     Now::set('session', session(SITE_NAME));
     $controllerFile = Config::get('mvc.dir', APPLICATION_PATH) . DS . 'controllers' . DS . $controllerName . '.php';
     if (!is_file($controllerFile)) {
         $controllerFile = Config::get('mvc.dir', APPLICATION_PATH) . DS . 'controllers' . DS . 'static.php';
         $action = 404;
     }
     require_once $controllerFile;
     $class = '\\Thin\\' . ucfirst(strtolower(SITE_NAME)) . ucfirst(Inflector::lower($controllerName)) . 'Controller';
     Now::set('request', (new Object())->populate($_REQUEST));
     $controller = new $class($action);
     if (true === $render) {
         $this->render($controller);
     }
 }
示例#16
0
文件: static.php 项目: schpill/blog
 public function __construct($action)
 {
     $method = Request::method();
     $this->_name = 'static';
     $this->session = session(SITE_NAME);
     $this->me = lib('me');
     $this->action = $action;
     $this->bucket = new Bucket(SITE_NAME, URLSITE . 'bucket');
     if ($action == 404) {
         $this->routing();
     } else {
         $action = Inflector::lower($method) . ucfirst(Inflector::camelize(strtolower($action)));
         $methods = get_class_methods($this);
         if (in_array($action, $methods)) {
             $this->{$action}();
         } else {
             RouterLib::is404();
         }
     }
 }
示例#17
0
 private function sanitize($_)
 {
     if (!is_string($_)) {
         return false;
     }
     if (empty($_)) {
         return false;
     }
     $stop = strlen($_);
     $_ = str_replace('/url?q=', '', Inflector::lower($_));
     for ($i = 0; $i < $stop; $i++) {
         if (Arrays::in($_[$i], array('&amp;', '"', '&', "'"))) {
             $stop = $i;
             $i = strlen($_);
         }
     }
     $url = '';
     for ($j = 0; $j < $stop; $j++) {
         $url .= $_[$j];
     }
     return rawurldecode($url);
 }
示例#18
0
文件: Factory.php 项目: schpill/thin
 public function __call($event, $args)
 {
     if (substr($event, 0, 3) == 'get') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($event, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         return $this->get($key);
     } elseif (substr($event, 0, 3) == 'set') {
         $value = Arrays::first($args);
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($event, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         if ($key == '__object') {
             throw new Exception("The key {$key} is protected.");
         }
         return $this->set($key, $value);
     }
     if (true === $this->__has($event)) {
         return $this->__fire($event, $args);
     } else {
         $value = Arrays::first($args);
         if (method_exists($this, $event)) {
             throw new Exception("The method {$event} is a native class' method. Please choose an other name.");
         }
         if (!is_callable($value)) {
             $closure = function () use($value) {
                 return $value;
             };
             $value = $closure;
         }
         $obj = $this->instance();
         $share = function () use($obj, $value) {
             $args = func_get_args();
             $args[] = $obj;
             return call_user_func_array($value, $args);
         };
         $eventable = $this->__event($event, $share);
         return $this;
     }
 }
示例#19
0
 public static function auto($sentence, $source = 'fr', $target = 'en')
 {
     $key = sha1(serialize(func_get_args()));
     $res = Data::query('translation', 'key = ' . $key);
     if (count($res)) {
         $obj = current($res);
         return $obj->getSentence();
     }
     $source = Inflector::lower($source);
     $target = Inflector::lower($target);
     $url = "http://api.mymemory.translated.net/get?q=" . urlencode($sentence) . "&langpair=" . urlencode($source) . "|" . urlencode($target);
     $res = dwn($url);
     $tab = json_decode($res, true);
     if (Arrays::exists('responseData', $tab)) {
         if (Arrays::exists('translatedText', $tab['responseData'])) {
             $translation = $tab['responseData']['translatedText'];
             $data = array('source' => $source, 'target' => $target, 'key' => $key, 'sentence' => $translation);
             Data::add('translation', $data);
             return $translation;
         }
     }
     return $sentence;
 }
示例#20
0
 public function __call($m, $a)
 {
     if (fnmatch('get*', $m)) {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($m, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         $args = [$key];
         if (!empty($a)) {
             $args[] = current($a);
         }
         return call_user_func_array([$this, 'get'], $args);
     } elseif (fnmatch('set*', $m)) {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($m, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         $args = [$key];
         $args[] = current($a);
         return call_user_func_array([$this, 'set'], $args);
     } elseif (fnmatch('forget*', $m)) {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($m, 6)));
         $key = Inflector::lower($uncamelizeMethod);
         $args = [$key];
         return call_user_func_array([$this, 'forget'], $args);
     }
 }
示例#21
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);
 }
示例#22
0
文件: Mobile.php 项目: schpill/thin
 /**
  * Search for a certain key in the rules array.
  * If the key is found the try to match the corresponding
  * regex agains the User-Agent.
  *
  * @param string $key
  * @param null $userAgent deprecated
  * @return mixed
  */
 protected function matchUAAgainstKey($key, $userAgent = null)
 {
     // Make the keys lowercase so we can match: isIphone(), isiPhone(), isiphone(), etc.
     $key = Inflector::lower($key);
     //change the keys to lower case
     $_rules = array_change_key_case($this->getRules());
     if (Arrays::exists($key, $_rules)) {
         if (empty($_rules[$key])) {
             return null;
         }
         return $this->match($_rules[$key], $userAgent);
     }
     return false;
 }
示例#23
0
文件: Orm.php 项目: schpill/thin
 private function _query($q)
 {
     //*GP* hr($q);
     $db = $this->_getConnexion();
     $key = $this->_dbName . '.' . $this->_tableName;
     /* On evite de refaire n fois les memes requetes select dans la meme instance */
     $cacheIt = true === $this->_buffer && !Arrays::in($key, $this->_bufferTables) && (Inflector::lower(substr($q, 0, 6)) == 'select' || Inflector::lower(substr($q, 0, 4)) == 'show' || Inflector::lower(substr($q, 0, 8)) == 'describe') ? true : false;
     if (true === $cacheIt) {
         $key = sha1($q . $this->_dbName);
         $buffer = $this->_buffer($key);
         if (false !== $buffer) {
             $result = $buffer;
         } else {
             $result = $db->prepare($q);
             $result->execute();
             if (false !== $result) {
                 $cols = array();
                 foreach ($result as $row) {
                     $cols[] = $row;
                 }
                 $result = $cols;
                 //*GP* ThinLog($q, DIR_LOGS . DS . date("Y-m-d") . '_queries.log', null, 'query');
             }
             if (true === $this->_buffer) {
                 $this->_buffer($key, $result);
             }
         }
     } else {
         $result = $db->prepare($q);
         $result->execute();
         //*GP* ThinLog($q, DIR_LOGS . DS . date("Y-m-d") . '_queries.log', null, 'query');
     }
     return $result;
 }
示例#24
0
 public function __call($m, $a)
 {
     if (fnmatch('retrieve*', $m) && strlen($m) > strlen('retrieve')) {
         $pivot = Inflector::lower(str_replace('retrieve', '', $m));
         return call_user_func_array([$this, 'retrieve'], [current($a), (string) $pivot]);
     }
     if (fnmatch('get*', $m) && strlen($m) > strlen('get')) {
         $pivot = Inflector::lower(str_replace('get', '', $m));
         $res = call_user_func_array([$this, 'retrieve'], [current($a), (string) $pivot]);
         $last = $m[strlen($m) - 1];
         if ('s' == $last) {
             return $res;
         }
         $row = $res->first();
         if (!$row) {
             $obj = current($a);
             $field = $pivot . '_id';
             $table = ucfirst($pivot);
             $row = Model::$table()->find((int) $obj->{$field}, false);
         }
         return $row;
     }
 }
示例#25
0
文件: Model.php 项目: noikiy/inovi
 /**
  * __call
  *
  * @param string $func func
  * @param mixed  $args args
  *
  * @return null
  */
 public function __call($func, $args)
 {
     if ($func == 'unset' && isset($args[0])) {
         $this->__unset($args[0]);
     }
     if (strpos($func, 'get') === 0 && strlen($func) > 3) {
         $key = Inflector::lower(substr($func, 3));
         if (method_exists($this, $func)) {
             return call_user_func(array($this, $func));
         }
         return $this->__get($key);
     }
     if (strpos($func, 'set') === 0 && strlen($func) > 3) {
         $key = Inflector::lower(substr($func, 3));
         if (method_exists($this, $func)) {
             return call_user_func(array($this, $func), isset($args[0]) ? $args[0] : null);
         }
         return $this->__set($key, isset($args[0]) ? $args[0] : null);
     }
 }
示例#26
0
文件: gma.php 项目: noikiy/inovi
 private function upload($field)
 {
     $bucket = container()->bucket();
     if (Arrays::exists($field, $_FILES)) {
         $fileupload = $_FILES[$field]['tmp_name'];
         $fileuploadName = $_FILES[$field]['name'];
         if (strlen($fileuploadName)) {
             $tab = explode(".", $fileuploadName);
             $ext = Inflector::lower(Arrays::last($tab));
             return $bucket->data(fgc($fileupload), $ext);
         }
     }
     return null;
 }
示例#27
0
 public function getImg($id, $size = 'large')
 {
     return 'http://photos.duproprio.com/img-' . Inflector::lower($size) . '-' . $id . '.jpg';
 }
示例#28
0
文件: File.php 项目: schpill/thin
 public static function download($fileLocation, $maxSpeed = 5120)
 {
     if (connection_status() != 0) {
         return false;
     }
     $tab = explode(DS, $fileLocation);
     $fileName = Arrays::last($tab);
     $extension = Inflector::lower(substr($fileName, strrpos($fileName, '.') + 1));
     /* List of File Types */
     $fileTypes['swf'] = 'application/x-shockwave-flash';
     $fileTypes['pdf'] = 'application/pdf';
     $fileTypes['exe'] = 'application/octet-stream';
     $fileTypes['zip'] = 'application/zip';
     $fileTypes['doc'] = 'application/msword';
     $fileTypes['docx'] = 'application/msword';
     $fileTypes['xls'] = 'application/vnd.ms-excel';
     $fileTypes['xlsx'] = 'application/vnd.ms-excel';
     $fileTypes['ppt'] = 'application/vnd.ms-powerpoint';
     $fileTypes['pptx'] = 'application/vnd.ms-powerpoint';
     $fileTypes['gif'] = 'image/gif';
     $fileTypes['png'] = 'image/png';
     $fileTypes['jpeg'] = 'image/jpg';
     $fileTypes['bmp'] = 'image/bmp';
     $fileTypes['jpg'] = 'image/jpg';
     $fileTypes['rar'] = 'application/rar';
     $fileTypes['ace'] = 'application/ace';
     $fileTypes['ra'] = 'audio/x-pn-realaudio';
     $fileTypes['ram'] = 'audio/x-pn-realaudio';
     $fileTypes['ogg'] = 'audio/x-pn-realaudio';
     $fileTypes['wav'] = 'video/x-msvideo';
     $fileTypes['wmv'] = 'video/x-msvideo';
     $fileTypes['avi'] = 'video/x-msvideo';
     $fileTypes['asf'] = 'video/x-msvideo';
     $fileTypes['divx'] = 'video/x-msvideo';
     $fileTypes['mp3'] = 'audio/mpeg';
     $fileTypes['mp4'] = 'audio/mpeg';
     $fileTypes['mpeg'] = 'video/mpeg';
     $fileTypes['mpg'] = 'video/mpeg';
     $fileTypes['mpe'] = 'video/mpeg';
     $fileTypes['mov'] = 'video/quicktime';
     $fileTypes['swf'] = 'video/quicktime';
     $fileTypes['3gp'] = 'video/quicktime';
     $fileTypes['m4a'] = 'video/quicktime';
     $fileTypes['aac'] = 'video/quicktime';
     $fileTypes['m3u'] = 'video/quicktime';
     $contentType = isAke($fileTypes, $extension, 'application/octet-stream');
     header("Cache-Control: public");
     header("Content-Transfer-Encoding: binary\n");
     header("Content-Type: {$contentType}");
     $contentDisposition = 'attachment';
     if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
         $fileName = preg_replace('/\\./', '%2e', $fileName, substr_count($fileName, '.') - 1);
         header("Content-Disposition: {$contentDisposition};filename=\"{$fileName}\"");
     } else {
         header("Content-Disposition: {$contentDisposition};filename=\"{$fileName}\"");
     }
     header("Accept-Ranges: bytes");
     $range = 0;
     $size = filesize($fileLocation);
     $range = isAke($_SERVER, 'HTTP_RANGE', null);
     if (!is_null($range)) {
         list($a, $range) = explode("=", $range);
         $range = repl($range, "-", $range);
         $size2 = $size - 1;
         $new_length = $size - $range;
         header("HTTP/1.1 206 Partial Content");
         header("Content-Length: {$new_length}");
         header('Content-Range: bytes ' . $range . $size2 . '/' . $size);
     } else {
         $size2 = $size - 1;
         header("Content-Range: bytes 0-{$size2}/{$size}");
         header("Content-Length: " . $size);
     }
     if ($size < 1) {
         die('Zero byte file! Aborting download');
     }
     $fp = fopen($fileLocation, "rb");
     fseek($fp, $range);
     while (!feof($fp) && connection_status() == 0) {
         set_time_limit(0);
         print fread($fp, 1024 * $maxSpeed);
         flush();
         ob_flush();
         sleep(1);
     }
     fclose($fp);
     exit;
     return connection_status() == 0 && !connection_aborted();
 }
示例#29
0
 public function __call($func, $argv)
 {
     if (substr($func, 0, 3) == 'get') {
         $data = $this->_session->getData();
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $var = Inflector::lower($uncamelizeMethod);
         if (isset($data->{$var})) {
             $this->checkTimeout();
             return $data->{$var};
         } else {
             return null;
         }
     } elseif (substr($func, 0, 3) == 'set') {
         $data = $this->_session->getData();
         $value = $argv[0];
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $var = Inflector::lower($uncamelizeMethod);
         if (false === $this->_isLocked) {
             $data->{$var} = $value;
         }
         return $this->save();
     } elseif (substr($func, 0, 6) == 'forget') {
         $data = $this->_session->getData();
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $var = Inflector::lower($uncamelizeMethod);
         if (false === $this->_isLocked) {
             $this->erase($var);
             return $data;
         }
         return $this->save();
     }
     if (!is_callable($func) || substr($func, 0, 3) !== 'set' || substr($func, 0, 3) !== 'get') {
         throw new \BadMethodCallException(__CLASS__ . ' => ' . $func);
     }
 }
示例#30
0
文件: Jsoneav.php 项目: schpill/thin
 public function __call($method, $parameters)
 {
     if (substr($method, 0, 6) == 'findBy') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 6)));
         $field = Inflector::lower($uncamelizeMethod);
         $value = Arrays::first($parameters);
         return $this->findBy($field, $value);
     } elseif (substr($method, 0, strlen('findObjectsBy')) == 'findObjectsBy') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, strlen('findObjectsBy'))));
         $field = Inflector::lower($uncamelizeMethod);
         $value = Arrays::first($parameters);
         return $this->findBy($field, $value, false, true);
     } elseif (substr($method, 0, 9) == 'findOneBy') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 9)));
         $field = Inflector::lower($uncamelizeMethod);
         $value = Arrays::first($parameters);
         return $this->findBy($field, $value, true);
     } else {
         $settings = isAke(self::$configs, $this->entity);
         $event = isAke($settings, $method);
         if (!empty($event)) {
             if (is_callable($event)) {
                 if (version_compare(PHP_VERSION, '5.4.0', ">=")) {
                     $event = $event->bindTo($this);
                 }
                 return call_user_func_array($event, $parameters);
             }
         } else {
             throw new Exception("The method '{$method}' is not callable.");
         }
     }
 }