当前位置: 首页>>代码示例>>PHP>>正文


PHP Thin\Inflector类代码示例

本文整理汇总了PHP中Thin\Inflector的典型用法代码示例。如果您正苦于以下问题:PHP Inflector类的具体用法?PHP Inflector怎么用?PHP Inflector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Inflector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __call

 public function __call($event, $args)
 {
     if (substr($event, 0, 3) == 'get' && strlen($event) > 3) {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($event, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         return $this->get($key);
     } elseif (substr($event, 0, 3) == 'set' && strlen($event) > 3) {
         $value = Arrays::first($args);
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($event, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         return $this->set($key, $value);
     }
     if (true === $this->__has($event)) {
         array_push($args, $this);
         return $this->__fire($event, $args);
     } else {
         if (method_exists($this, $event)) {
             throw new Exception("The method {$event} is a native class' method. Please choose an other name.");
         }
         $value = Arrays::first($args);
         if ($value instanceof Closure) {
             $eventable = $this->__event($event, $value);
         } else {
             $set = function () use($value) {
                 return $value;
             };
             $eventable = $this->__event($event, $set);
         }
         return $this;
     }
 }
开发者ID:noikiy,项目名称:inovi,代码行数:31,代码来源:Context.php

示例2: __call

 public function __call($event, $args)
 {
     if (substr($event, 0, 3) == 'get') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($event, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         return self::get($key);
     } elseif (substr($event, 0, 3) == 'set') {
         $value = Arrays::first($args);
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($event, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         return self::set($key, $value);
     }
     if (true === self::__has($event)) {
         return self::__fire($event, $args);
     } else {
         $value = Arrays::first($args);
         if ($value instanceof Closure) {
             $eventable = self::__event($event, $value);
         } else {
             $set = function () use($value) {
                 return $value;
             };
             $eventable = self::__event($event, $set);
         }
     }
 }
开发者ID:schpill,项目名称:thin,代码行数:26,代码来源:Di.php

示例3: __call

 public function __call($func, $argv)
 {
     if (substr($func, 0, 3) == 'get' && strlen($func) > 3) {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $var = Inflector::lower($uncamelizeMethod);
         if (isset($this->{$var})) {
             $this->clean();
             return $this->{$var};
         } else {
             return null;
         }
     } elseif (substr($func, 0, 3) == 'set' && strlen($func) > 3) {
         $value = $argv[0];
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $var = Inflector::lower($uncamelizeMethod);
         $this->{$var} = $value;
         return $this->save();
     } elseif (substr($func, 0, 6) == 'forget' && strlen($func) > 6) {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 6)));
         $var = Inflector::lower($uncamelizeMethod);
         $this->erase($var);
         return $this->save();
     }
     $id = sha1($func);
     if (isset($this->{$id})) {
         if ($this->{$id} instanceof \Closure) {
             return call_user_func_array($this->{$id}, $argv);
         }
     }
     if (!is_callable($func) || substr($func, 0, 3) !== 'set' || substr($func, 0, 3) !== 'get') {
         throw new \BadMethodCallException(__CLASS__ . ' => ' . $func);
     }
 }
开发者ID:schpill,项目名称:thin,代码行数:33,代码来源:Redis.php

示例4: run

 public function run()
 {
     if (fnmatch('*cli*', php_sapi_name())) {
         $dir = Config::get('dir.schedules', APPLICATION_PATH . DS . 'schedules');
         if (is_dir($dir)) {
             Timer::start();
             Cli::show("Start of execution", 'COMMENT');
             $files = glob($dir . DS . '*.php');
             foreach ($files as $file) {
                 require_once $file;
                 $object = str_replace('.php', '', Arrays::last(explode(DS, $file)));
                 $class = 'Thin\\' . ucfirst(Inflector::camelize($object . '_schedule'));
                 $instance = lib('app')->make($class);
                 $methods = get_class_methods($instance);
                 Cli::show("Start schedule '{$object}'", 'COMMENT');
                 foreach ($methods as $method) {
                     $when = $this->getWhen($instance, $method);
                     $isDue = $this->isDue($object, $method, $when);
                     if (true === $isDue) {
                         Cli::show("Execution of {$object}->{$method}", 'INFO');
                         $instance->{$method}();
                     } else {
                         Cli::show("No need to execute {$object}->{$method}", 'QUESTION');
                     }
                 }
             }
             Cli::show("Time of execution [" . Timer::get() . " s.]", 'SUCCESS');
             Cli::show("end of execution", 'COMMENT');
         }
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:31,代码来源:schedule.php

示例5: __destruct

 public function __destruct()
 {
     /* On efface le model de la base tampon et on vide la base */
     $modelFile = APPLICATION_PATH . DS . 'models' . DS . 'Bigdata' . DS . 'models' . DS . Inflector::lower($this->to->db) . DS . ucfirst(Inflector::lower($this->to->table)) . '.php';
     File::delete($modelFile);
     $this->to->drop();
 }
开发者ID:schpill,项目名称:standalone,代码行数:7,代码来源:Transaction.php

示例6: __construct

 public function __construct($db)
 {
     $this->orm = $db;
     $this->db = $db->db();
     $this->table = $db->table();
     $dir = Config::get('dir.blizz.store', session_save_path());
     if (!is_dir($dir)) {
         File::mkdir($dir);
     }
     $dir .= DS . Inflector::urlize(Inflector::uncamelize($this->db));
     if (!is_dir($dir)) {
         File::mkdir($dir);
     }
     $this->dir = $dir . DS . Inflector::urlize(Inflector::uncamelize($this->table));
     if (!is_dir($this->dir)) {
         File::mkdir($this->dir);
     }
     $file = $this->dir . DS . 'data.db';
     $new = false;
     if (!is_file($file)) {
         File::create($file);
         $new = true;
         File::put($this->dir . DS . 'age.blizz', '');
     }
     $link = new SQLite3($file);
     Now::set("blizz.link.{$this->db}.{$this->table}", $link);
     if ($new) {
         $this->init();
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:30,代码来源:blizzstore.php

示例7: __callStatic

 public static function __callStatic($fn, $args)
 {
     $method = Inflector::upper($fn);
     if (count($args) < 2) {
         throw new Exception("You must provide at least a path and a mvc pattern.");
     }
     $path = $args[0];
     $mvc = $args[1];
     $argsRoute = [];
     $optionsRoute = [];
     if (count($args) > 2) {
         $argsRoute = $args[2];
         if (count($args) > 3) {
             array_shift($args);
             array_shift($args);
             array_shift($args);
             $optionsRoute = $args;
         }
     }
     list($module, $controller, $action) = explode('::', $mvc, 3);
     if (!isset($module) || !isset($controller) || !isset($action)) {
         throw new Exception("MVC '{$mvc}' is incorrect.");
     }
     return ['name' => Inflector::lower($method) . '::' . $module . '::' . $controller . '::' . $action, 'method' => $method, 'path' => $path, 'module' => $module, 'controller' => $controller, 'action' => $action, 'args' => $argsRoute, 'options' => $optionsRoute];
 }
开发者ID:schpill,项目名称:standalone,代码行数:25,代码来源:Route.php

示例8: callback

 public static function callback($class, $method, Closure $cb)
 {
     $callbackClass = ucfirst(Inflector::lower($class));
     if (!class_exists('Thin\\' . $callbackClass)) {
         eval("namespace Thin; class {$callbackClass} extends Alias {}");
     }
     static::$cb[$callbackClass][$method] = $cb;
 }
开发者ID:schpill,项目名称:thin,代码行数:8,代码来源:Alias.php

示例9: __callStatic

 public static function __callStatic($method, $args)
 {
     if (count($args)) {
         $type = Inflector::upper($method);
         $fnArgs = array_merge([$type], $args);
         return call_user_func_array('staticLog', $fnArgs);
     }
     throw new Exception('You must provide a message to log.');
 }
开发者ID:schpill,项目名称:standalone,代码行数:9,代码来源:Log.php

示例10: register

 public function register()
 {
     $args = func_get_args();
     if (count($args) < 1 || count($args) > 1) {
         throw new Exception("You need to provide a helper to register.");
     }
     $helper = reset($args);
     $this->type = 'helpers';
     $this->file = APPLICATION_PATH . DS . 'helpers' . DS . ucfirst(Inflector::lower($helper)) . DS . ucfirst(Inflector::lower($helper)) . '.php';
     $this->class = 'ThinHelper\\' . ucfirst(Inflector::lower($helper)) . '\\' . ucfirst(Inflector::lower($helper));
     return $this->factory();
 }
开发者ID:schpill,项目名称:thin,代码行数:12,代码来源:Helper.php

示例11: createFromGlobals

 /**
  * Creates a new request with values from PHP's super globals.
  *
  * @return Request A new request
  *
  * @api
  */
 public static function createFromGlobals()
 {
     $request = new static($_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER);
     if ((0 === strpos($request->server->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') || 0 === strpos($request->server->get('HTTP_CONTENT_TYPE'), 'application/x-www-form-urlencoded')) && in_array(\Thin\Inflector::upper($request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE', 'PATCH'))) {
         parse_str($request->getContent(), $data);
         if (magic_quotes()) {
             $data = arrayStripslashes($data);
         }
         $request->request = new ParameterBag($data);
     }
     return $request;
 }
开发者ID:noikiy,项目名称:inovi,代码行数:19,代码来源:ThinRequest.php

示例12: run

function run($lib, $args = null)
{
    $lib = Inflector::lower(Inflector::uncamelize($lib));
    $script = str_replace('_', DS, $lib) . '.php';
    if (fnmatch('*_*', $lib)) {
        $class = 'Thin\\' . str_replace('_', '\\', $lib);
        $tab = explode('\\', $class);
        $first = $tab[1];
        $class = str_replace('Thin\\' . $first, 'Thin\\' . ucfirst($first) . 'Libs', $class);
        if (count($tab) > 2) {
            for ($i = 2; $i < count($tab); $i++) {
                $seg = trim($tab[$i]);
                $class = str_replace('\\' . $seg, '\\' . ucfirst($seg), $class);
            }
        }
    } else {
        $class = 'Thin\\' . ucfirst($lib) . 'Libs';
    }
    $file = __DIR__ . DS . 'libs' . DS . $script;
    if (is_file($file)) {
        require_once $file;
        if (empty($args)) {
            return new $class();
        } else {
            if (!is_array($args)) {
                if (is_string($args)) {
                    if (fnmatch('*,*', $args)) {
                        $args = explode(',', str_replace(', ', ',', $args));
                    } else {
                        $args = [$args];
                    }
                } else {
                    $args = [$args];
                }
            }
            $methods = get_class_methods($class);
            if (in_array('instance', $methods)) {
                return call_user_func_array([$class, 'instance'], $args);
            } else {
                return construct($class, $args);
            }
        }
    }
    if (class_exists('Thin\\' . $lib)) {
        $c = 'Thin\\' . $lib;
        return new $c();
    }
    if (class_exists($lib)) {
        return new $lib();
    }
    throw new Exception("The library {$class} does not exist.");
}
开发者ID:schpill,项目名称:blog,代码行数:52,代码来源:helpers.php

示例13: prepare

 public function prepare($text)
 {
     $slugs = explode(' ', Inflector::slug($text, ' '));
     if (count($slugs)) {
         $collection = array();
         foreach ($slugs as $slug) {
             if (strlen($slug) > 1) {
                 if (!Arrays::in($slug, $collection)) {
                     array_push($collection, $slug);
                 }
             }
         }
         asort($collection);
     }
     return $collection;
 }
开发者ID:schpill,项目名称:thin,代码行数:16,代码来源:Fulltext.php

示例14: __callStatic

 public static function __callStatic($method, $args)
 {
     $db = Inflector::uncamelize($method);
     if (fnmatch('*_*', $db)) {
         list($database, $table) = explode('_', $db, 2);
     } else {
         $database = SITE_NAME;
         $table = $db;
     }
     if (empty($args)) {
         return new Redis($database, $table);
     } elseif (count($args) == 1) {
         $id = Arrays::first($args);
         if (is_numeric($id)) {
             return with(new Redis($database, $table))->find($id);
         }
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:18,代码来源:Cacher.php

示例15: __callStatic

 public static function __callStatic($method, $args)
 {
     $db = Inflector::uncamelize($method);
     if (fnmatch('*_*', $db)) {
         list($database, $table) = explode('_', $db, 2);
     } else {
         $database = SITE_NAME;
         $table = $db;
     }
     if (empty($args)) {
         return Db::instance($database, $table);
     } elseif (count($args) == 1) {
         $id = current($args);
         if (is_numeric($id)) {
             return Db::instance($database, $table)->find((int) $id);
         }
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:18,代码来源:Entity.php


注:本文中的Thin\Inflector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。