/** * Get an item from the cache or get a default value * * @param $name * @param callable $callback * @param null $minutes * * @return mixed */ public function cache($name, Closure $callback, $minutes = null) { fire(new CacheCallingEvent($name)); // Prefix the name with the current client if nessesary if (!env('APP_CACHING', false)) { fire(new CacheCalledEvent($name, $minutes, false)); return $callback(); } if ($minutes) { fire(new CacheCalledEvent($name, $minutes, true)); return app(CacherService::class)->remember($name, $minutes, $callback); } fire(new CacheCalledEvent($name, $minutes, true)); return app(CacherService::class)->sear($name, $callback); }
/** * Process the Detection * * @throws \Melon\Current\Exceptions\NotDetectableException * @return mixed|null */ public function run($lookup = null) { $name = $this->getName(); $key = $name . '_detection'; debugger()->start($key, "[{$name}] Detection."); foreach ($this->getLookups($lookup) as $lookup) { $method = 'try' . $lookup; if (!method_exists($this, $method)) { continue; } if ($this->detected = $this->{$method}()) { debugger()->stop($key); fire(new CurrentEntityDetectedEvent($name, $this->detected, $lookup)); return $this->handleDetectionComplete($lookup); } } debugger()->stop($key); throw new NotDetectableException($this->getName()); }
<?php require_once __DIR__ . '/libs/worker_boot.php'; $payload = decryptPayload(getPayload()); fire($payload); function fire($payload) { echo $payload; }
public function __call($func, $argv) { $key = sha1('orm' . $this->_token); $orm = isAke($this->values, $key, false); $key = sha1('model' . $this->_token); $dbjson = isAke($this->values, $key, false); if (substr($func, 0, 4) == 'link' && false !== $orm) { $value = Arrays::first($argv); $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 4))); $var = Inflector::lower($uncamelizeMethod); if (!empty($var)) { $var = setter($var . '_id'); $this->{$var}($value->id); return $this; } } elseif (substr($func, 0, 3) == 'get') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $var = Inflector::lower($uncamelizeMethod); if (isset($this->{$var})) { if (isset($this->thin_type)) { $type = $this->thin_type; Data::getModel($type); $settings = Arrays::exists($type, Data::$_settings) ? Data::$_settings[$type] : []; if (Arrays::exists('relationships', $settings)) { if (Arrays::exists($var, $settings['relationships'])) { return Data::getById($var, $this->{$var}); } } } if (Arrays::is($this->{$var}) && count($argv) == 1) { $o = new self(); $getter = getter(Arrays::first($argv)); $o->populate($this->{$var}); return $o->{$getter}(); } if ($this->{$var} instanceof Closure) { if (is_callable($this->{$var}) && count($argv)) { return call_user_func_array($this->{$var}, $argv); } } return count($argv) && is_null($this->{$var}) ? Arrays::first($argv) : $this->{$var}; } else { if (isset($this->db_instance)) { return $this->db_instance->getValue($this, $var); } if (isset($this->thin_type)) { $type = $this->thin_type; Data::getModel($type); $settings = Arrays::exists($type, Data::$_settings) ? Data::$_settings[$type] : []; $relationships = Arrays::exists('relationships', $settings) ? $settings['relationships'] : []; if (Arrays::exists($var, $relationships) && 's' == $var[strlen($var) - 1]) { if (Arrays::exists($var, $relationships)) { $res = dm(substr($var, 0, -1))->where("{$type} = " . $this->id)->get(); $collection = []; if (count($res)) { foreach ($res as $obj) { array_push($collection, $obj); } } return $collection; } } elseif (Arrays::exists('defaultValues', $settings)) { if (Arrays::is($settings['defaultValues'])) { if (Arrays::exists($this->{$var}, $settings['defaultValues'])) { return $settings['defaultValues'][$this->{$var}]; } } } } if (count($argv) == 1) { return Arrays::first($argv); } return null; } } elseif (substr($func, 0, 3) == 'has') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $var = Inflector::lower($uncamelizeMethod); if (isset($this->{$var})) { return !empty($this->{$var}); } elseif (isset($this->db_instance)) { return $this->db_instance->hasValue($this, $var); } } elseif (substr($func, 0, 3) == 'set') { $value = Arrays::first($argv); $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $var = Inflector::lower($uncamelizeMethod); if (!empty($var)) { if (isset($this->thin_type)) { Data::getModel($this->thin_type); $fields = Arrays::exists($this->thin_type, Data::$_fields) ? Data::$_fields[$this->thin_type] : []; if (!Arrays::exists($var, $fields)) { throw new Exception($var . ' is not defined in the model => ' . $this->thin_type); } else { $settingsField = $fields[$var]; if (Arrays::exists('checkValue', $settingsField)) { $functionCheck = $settingsField['checkValue']; $value = $functionCheck($value); } if (is_object($value)) { if (isset($value->thin_type)) { if ($value->thin_type == $var) { $value = $value->id; } } } } } $this->{$var} = $value; if (!Arrays::in($var, $this->_fields)) { $this->_fields[] = $var; } if (isset($this->is_thin_object)) { $name = $this->is_thin_object; $objects = Utils::get('thinObjects'); $this->values = null; $objects[$name] = $this; Utils::set('thinObjects', $objects); } if (isset($this->is_app)) { if (true === $this->is_app) { Utils::set('ThinAppContainer', $this); } } } elseif (isset($this->db_instance)) { return $this->db_instance->setValue($this, $var, $value); } return $this; } elseif (substr($func, 0, 3) == 'add') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $var = Inflector::lower($uncamelizeMethod) . 's'; $value = Arrays::first($argv); if (!isset($this->{$var})) { $this->{$var} = []; } if (!Arrays::is($this->{$var})) { $this->{$var} = []; } array_push($this->{$var}, $value); return $this; } elseif (substr($func, 0, 6) == 'remove') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 6))); $var = Inflector::lower($uncamelizeMethod) . 's'; $value = Arrays::first($argv); if (isset($this->{$var})) { if (Arrays::is($this->{$var})) { if (count($this->{$var})) { $remove = false; foreach ($this->{$var} as $key => $tmpValue) { $comp = md5(serialize($value)) == md5(serialize($tmpValue)); if (true === $comp) { $remove = true; break; } } if (true === $remove) { unset($this->{$var}[$key]); } } } } return $this; } if (Arrays::in($func, $this->_fields)) { if ($this->{$func} instanceof Closure) { return call_user_func_array($this->{$func}, $argv); } } if (Arrays::exists($func, $this->_closures)) { if ($this->_closures[$func] instanceof Closure) { return call_user_func_array($this->_closures[$func], $argv); } } if (isset($this->_token)) { $id = sha1($func . $this->_token); if (Arrays::is($this->values)) { if (Arrays::exists($id, $this->values)) { return call_user_func_array($this->values[$id], $argv); } } } if (true === hasEvent($func)) { array_push($argv, $this); return fire($func, $argv); } if (!is_callable($func) || substr($func, 0, 6) !== 'array_' || substr($func, 0, 3) !== 'set' || substr($func, 0, 3) !== 'get' || substr($func, 0, 3) !== 'has' || substr($func, 0, 3) !== 'add' || substr($func, 0, 6) !== 'remove') { $callable = strrev(repl('_', '', $func)); if (!is_callable($callable)) { if (method_exists($this, $callable)) { return call_user_func_array(array($this, $callable), $argv); } } else { return call_user_func_array($callable, $argv); } if (isset($this->thin_litedb)) { $closure = isAke($this->thin_litedb->closures, $func); if (!empty($closure) && $closure instanceof Closure) { return $closure($this); } } if (isset($this->db_instance)) { return $this->db_instance->{$func}($this, $var, $value); call_user_func_array(array($this->db_instance, $func), array_merge(array($this), $argv)); } if (false !== $orm) { $db = call_user_func_array($orm, []); $fields = array_keys($db->map['fields']); if (Arrays::in($func, $fields)) { if (!count($argv)) { return $this->{$func}; } else { $setter = setter($func); $this->{$setter}(Arrays::first($argv)); return $this; } } $tab = str_split($func); $many = false; if (Arrays::last($tab) == 's') { array_pop($tab); $table = implode('', $tab); $many = true; } else { $table = $func; } $object = count($argv) == 1 ? Arrays::first($argv) : false; $model = model($table); return true === $many ? $model->where($db->table . '_id = ' . $this->id)->exec($object) : $model->where($db->table . '_id = ' . $this->id)->first($object); } if (false !== $dbjson) { $db = $this->model()->db(); $fields = $db->fields(); $modelMethods = get_class_methods('Dbjson\\Model'); if (Arrays::in($func, $fields)) { if (!count($argv)) { return $this->{$func}; } else { $setter = setter($func); $this->{$setter}(Arrays::first($argv)); return $this; } } if (Arrays::in($func, $modelMethods)) { return call_user_func_array([$this->model(), $func], $argv); } $tab = str_split($func); $many = false; if (Arrays::last($tab) == 's') { array_pop($tab); $table = implode('', $tab); $many = true; } else { $table = $func; } $object = count($argv) == 1 ? Arrays::first($argv) : true; $model = jdb($db->db, $table); return true === $many ? $model->where($db->table . '_id = ' . $this->id)->exec($object) : $model->where($db->table . '_id = ' . $this->id)->first($object); } return null; } return call_user_func_array($func, array_merge(array($this->getArrayCopy()), $argv)); }
if ($pid < 0) { die("fork failed"); } elseif ($pid > 0) { //echo "parent process \n"; } else { echo "child process {$i} is born. \n"; switch ($i) { case 0: wait(); break; case 1: wait(); break; case 2: sleep(1); fire(); break; } } } while (pcntl_waitpid(0, $status) != -1) { $status = pcntl_wexitstatus($status); echo "Child {$status} completed\n"; } function wait() { $event = new SyncEvent("UniqueName"); echo "before waiting. \n"; $event->wait(); echo "after waiting. \n"; exit;
<?php require __DIR__ . '/../bootstrap/autoload.php'; $app = (require_once __DIR__ . '/../bootstrap/start.php'); use Illuminate\Encryption\Encrypter; $app->setRequestForConsoleEnvironment(); $app->boot(); use App\Models\User; $payload = getAndDecryptPayload(getPayload()); print_r($payload); fire($payload->ids); function fire($ids) { if (strpos($ids[0], ',') !== FALSE) { $ids = explode(',', $ids[0]); } foreach ($ids as $id) { $user = User::find($id); echo "Sending mail to {$user->email} \n"; Mail::send('mail.template', array('firstname' => $user->first_name), function ($message) use($user) { $message->to($user->email, $user->first_name)->subject('Welcome to the Laravel 4 And Iron.io!'); }); } } function getAndDecryptPayload($payload) { $crypt = new Encrypter(Config::get('app.key')); $payload = $crypt->decrypt($payload); return json_decode(json_encode($payload), FALSE); }
function editProductImg($data, $id) { unset($data['image_id']); $query = $this->db->update('product_image', $data, array('image_id' => $id)); fire($this->db->last_query()); return $query; }
/** * Return the full path to an asset file * * @param string $key * @return string */ function assetPath($key) { return fire('asset')->path($key); }
/** * Returns the template for the current request * * @return string */ function content() { return fire('template.layout')->content(); }