作者:schpil
项目:thi
/**
* Resolve an array of commands through the application.
*
* @param array|dynamic $commands
* @return void
*/
public function resolveCommands($commands)
{
$commands = Arrays::isArray($commands) ? $commands : func_get_args();
foreach ($commands as $command) {
$this->resolve($command);
}
}
作者:schpil
项目:thi
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);
}
}
}
作者:noiki
项目:inov
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;
}
}
作者:schpil
项目:standalon
/**
* Constructor
*
* @param array $config
*/
public function __construct(array $config = [])
{
// Populate Keyring
Keyring::setAppKey($config['AK']);
// Application Key
Keyring::setAppSecret($config['AS']);
// Application Secret
Keyring::setConsumerKey($config['CK']);
// Consumer Key
// Backward compatibility
if (Arrays::exists('RG', $config)) {
Keyring::setAppUrlRegion($config['RG']);
// Region
} else {
Keyring::setAppUrlRegion("FR");
}
if (Arrays::exists('protocol', $config)) {
Keyring::setAppHost($config['protocol']);
// protocol
} else {
Keyring::setAppHost(static::$zeliftApiProtocol);
}
if (Arrays::exists('host', $config)) {
Keyring::setAppProtocol($config['host']);
// host
} else {
Keyring::setAppProtocol(static::$zeliftApiHost);
}
}
作者:schpil
项目:standalon
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');
}
}
}
作者:schpil
项目:standalon
/**
* Getter
* @param mixed $key
* @return mixed
*/
public function __get($key)
{
if (Arrays::exists($key, $this->data)) {
return $this->data[$key];
} else {
return false;
}
}
作者:schpil
项目:thi
/**
* Get an Instantiated ReflectionClass.
*
* @param string $class Optional name of a class
* @return mixed null or a ReflectionClass instance
* @throws Exception if class was not found
*/
public function get($class = null)
{
$class = $this->getClass($class);
if (Arrays::exists($class, $this->reflections)) {
return $this->reflections[$class];
}
throw new Exception("Class not found: {$class}");
}
作者:schpil
项目:standalon
public function beginTransaction()
{
$last = Arrays::last(explode(DS, $this->dir));
$target = str_replace(DS . $last, DS . 'copy.' . $last, $this->dir);
File::cpdir($this->dir, $target);
$this->dir = $target;
return $this;
}
作者:schpil
项目:thi
/**
* Creates a new navigation container
*
* @param array $pages [optional] pages to add
* @throws Exception if $pages is invalid
*/
public function __construct($pages = null)
{
if (Arrays::is($pages)) {
$this->addPages($pages);
} elseif (null !== $pages) {
throw new Exception('Invalid argument: $pages must be an array or null');
}
}
作者:schpil
项目:thi
/**
* where()
* Sets where object
* @access public
* @param string $where
* @param string $value
* @return \Thin\Webquery
*/
public function where($where = null, $value = null)
{
if (Arrays::is($this->where)) {
$this->whereKey = count($this->where) + 1;
}
$this->where[$this->whereKey]['attr'] = $where;
$this->where[$this->whereKey]['value'] = $value;
return $this;
}
作者:schpil
项目:standalon
/**
* Construct new RangeQuery component
*
* @return \ElasticSearch\DSL\RangeQuery
* @param array $options
*/
public function __construct(array $options = [])
{
$this->fieldname = key($options);
$values = Arrays::first($options);
if (Arrays::is($values)) {
foreach ($values as $key => $val) {
$this->{$key} = $val;
}
}
}
作者:schpil
项目:thi
public function remove($id)
{
if (!Arrays::exists($id, $this->services)) {
throw new InvalidArgumentException(sprintf('Service "%s" is not defined.', $id));
}
list($prefix, $sid) = $this->getPrefixAndSid($id);
if ($prefix) {
unset($this->prefixed[$prefix][$sid]);
}
unset($this->services[$id]);
}
作者:schpil
项目:standalon
public function __construct(array $array)
{
$this->key = sha1(serialize($array));
if (Arrays::isAssoc($array)) {
$tab = new SplFixedArray(1);
$tab[0] = $array;
$this->key .= 'AAA';
} else {
$tab = SplFixedArray::fromArray($array);
}
lib('resource')->set($this->key, $tab);
}
作者:schpil
项目:standalon
public function read($name, $default = null)
{
$file = $this->getFile($name);
$content = $this->import($file);
if ($content) {
if (Arrays::isAssoc($content)) {
return $content;
}
return current($content);
}
return $default;
}
作者:schpil
项目:standalon
/**
* Get or set a config
*
* @param string $key
* @param mixed $value
* @throws \Exception
* @return array|void
*/
public function config($key, $value = null)
{
if (Arrays::is($key)) {
$this->config = $key + $this->config;
} else {
if ($value !== null) {
$this->config[$key] = $value;
}
if (!isset($this->config[$key])) {
throw new Exception("Configuration key `type` is not set");
}
return $this->config[$key];
}
}
作者:schpil
项目:thi
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;
}
作者:schpil
项目:standalon
private static function eagerly($mongo, &$parents, $include)
{
$first = reset($parents);
$mongo->attributes = $first->attributes;
$relationship = $mongo->{$include}();
$mongo->attributes = $_ids = array();
foreach ($parents as &$parent) {
$_ids[] = $parent->_id;
$parent->ignore[$include] = Arrays::in($mongo->relating, array('has_many', 'has_and_belongs_to_many')) ? array() : null;
}
if (Arrays::in($relating = $mongo->relating, array('has_one', 'has_many', 'belongs_to'))) {
static::$relating($relationship, $parents, $mongo->relating_key, $include, $_ids);
} else {
static::manyToMany($relationship, $parents, $mongo->relating_key, $mongo->relating_table, $include, $_ids);
}
}
作者:schpil
项目:standalon
public function __construct()
{
$class = get_called_class();
if (strstr($class, '\\')) {
$class = Arrays::last(explode('\\', $class));
$class = str_replace('Model_', '', $class);
}
if (fnmatch('*_*', $class)) {
list($database, $table) = explode('_', $class, 2);
} else {
$database = SITE_NAME;
$table = $class;
}
self::$db = Db::instance($database, $table);
$this->model = self::$db->model(func_get_args());
}
作者:schpil
项目:standalon
private function getOrm($seg)
{
if (!count($seg)) {
throw new \Exception('Query is invalid.');
}
$seg = Arrays::first($seg);
$table = isAke($seg, 'table', false);
if (!$table) {
throw new \Exception('Query is invalid.');
}
if (fnmatch('*.*', $table)) {
list($database, $table) = explode('.', $table);
} else {
$database = SITE_NAME;
}
return jdb($database, $table);
}
作者:schpil
项目:standalon
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 = Arrays::first($args);
if (is_numeric($id)) {
return Db::instance($database, $table)->find($id);
}
}
}