/** @dataProvider dataMerge */ public function testMerge($mode, $newBarValue) { $store = new Store(':'); $store->set('foo:bar', 'baz'); $mergeData = ['foo' => ['bar' => 'quux', 'fizz' => 'buzz']]; $store->merge($mergeData, $mode); self::assertEquals($newBarValue, $store->get('foo:bar')); self::assertEquals('buzz', $store->get('foo:fizz')); }
public function testPushAdvanced() { $store = new Store(); $pair = new Pair('key', 'value'); $store->push($pair); $store->push(__DIR__ . '/data/php.ini'); $store->push(__DIR__ . '/data/test.xml'); $this->assertEquals('John', $store->get('firstName')); $store->push(new Pair('firstName', 'Paul')); $this->assertEquals('Paul', $store->get('firstName')); $this->assertEquals('Off', $store->get('asp_tags')); }
/** * @covers QueueController::Add * @todo Implement testAdd(). */ public function testAdd() { $person = Person::factory('adult'); $person->name = 'Poehavshiy'; $person->add(); $store = Store::factory('Grocery'); $store->name = 'Prison'; $store->add(); $product = new Product(); $product->name = 'Sladkiy hleb'; $product->add(); $request = Application::getInstance()->request; $request->setParams(array('storeId' => $store->id, 'personId' => $person->id, 'product_' . $product->id => 'on')); $personId = $request->p('personId'); $storeId = $request->p('storeId'); $store = Store::get($storeId); $person = Person::get($personId); $store->queue->add($person); $person->basket->drop(); $name = 'product_' . $product->id; $value = $product; if (preg_match_all('/^product_(\\d+)$/', $name, $matches)) { $person->basket->add(Product::get($matches[1][0])); } }
protected static function load_classes() { $store_key = array(__DIR__, '__autoload'); if (Store::has($store_key)) { $classes = Store::get($store_key); } else { $classes = array(); $modules = array(); $dir = path('libs'); $itr = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); $pattern = '/^' . preg_quote($dir, '/') . '\\/(.+?)\\.php$/'; foreach ($itr as $elem) { if ($elem->isFile() && preg_match($pattern, $elem->getPathname(), $match)) { $class_name = $elem->getBasename('.php'); if ($class_name == basename($elem->getPath())) { $modules[$class_name] = str_replace('/', '.', substr($elem->getPath(), strlen($dir) + 1)); } else { if ($class_name !== __CLASS__) { $classes[$class_name] = str_replace('/', '.', $match[1]); } } } } foreach ($modules as $module_name => $module_path) { foreach ($classes as $class_name => $class_path) { if (strpos($class_path, $module_path) === 0) { unset($classes[$class_name]); } } } $classes = $modules + $classes; Store::set($store_key, $classes); } self::$classes = $classes; }
/** * Get current flash message from session. * * @return void */ private function getFromSession() { if ($this->exists()) { $flashes = $this->session->get($this->key); foreach ($flashes as $flash) { $this->current->push(new Flash($flash['level'], $flash['message'])); } } }
private function lookupWordlists() { foreach ($this->bitmasks as $mask) { $addend = Store::get(Store::WORDLIST, $mask); if ($addend) { $this->wordlists = array_merge($this->wordlists, $addend); } } }
public static function unread_count(OpenpearMaintainer $maintainer) { $key = array('openpear_message_unread', $maintainer->id()); if (Store::has($key)) { return Store::get($key); } $unread_messages_count = C(__CLASS__)->find_count(Q::eq('maintainer_to_id', $maintainer->id()), Q::eq('unread', true)); Store::set($key, $unread_messages_count); return $unread_messages_count; }
public function Remove() { $this->_response()->asJSON(); try { $store = Store::get($this->_request()->g('id')); $store->remove(); return array('success' => 1); } catch (Exception $e) { return array('error' => $e->getMessage()); } }
function save($object = '', $related_field = '') { if (!$this->exists()) { $o = new Store(); $o->select_max('position'); $o->get(); if (count($o->all) != 0) { $max = $o->position + 1; $this->position = $max; } else { $this->postion = 1; } } return parent::save($object, $related_field); }
/** * linktitleHandler */ public static function linktitleHandler($url) { if (module_const('is_cache', false)) { $store_key = array('__hatenaformat_linktitlehandler', $url); if (Store::has($store_key)) { return Store::get($store_key); } } if (Tag::setof($title, Http::read($url), 'title')) { $url = $title->value(); if (module_const('is_cache', false)) { Store::set($store_key, $url, self::CACHE_EXPIRE); } } return $url; }
/** * Сохраняет информацию об ассортименте магазина. * * Принимает: storeId, product_id1, product_id2, ... * * @return type */ public function Save() { $this->_response()->asJSON(); try { $store = Store::get($this->_request()->p('storeId')); $map = array(); foreach ($_POST as $name => $value) { if (preg_match_all('/^product_(\\d+)$/', $name, $matches)) { $map[$matches[1][0]] = $value; } } $store->assortment->map($map); return array('success' => true); } catch (Exception $e) { return array('error' => $e->getMessage()); } }
/** * チェンジセットを取得する * @param int $revision * @param bool $cache * @return OpenpearChangeset **/ public static function get_changeset($revision, $cache = true) { $cache_key = self::cache_key($revision); if ($cache) { if (isset(self::$cached_changesets[$revision])) { return self::$cached_changesets[$revision]; } else { if (Store::has($cache_key)) { $changeset = Store::get($cache_key); self::$cached_changesets[$revision] = $changeset; return $changeset; } } } $changeset = C(__CLASS__)->find_get(Q::eq('revision', $revision)); Store::set($cache_key, $changeset); return $changeset; }
/** * メンテナ情報を取得する * @param int $id * @param bool $cache * @return OpenpearMaintainar **/ public static function get_maintainer($id, $cache = true) { $cache_key = self::cache_key($id); if ($cache) { Log::debug('cache on'); if (isset(self::$cached_maintainers[$id])) { return self::$cached_maintainers[$id]; } else { if (Store::has($cache_key)) { $maintainer = Store::get($cache_key); self::$cached_maintainers[$id] = $maintainer; return $maintainer; } } } $maintainer = C(__CLASS__)->find_get(Q::eq('id', $id)); Store::set($cache_key, $maintainer, OpenpearConfig::object_cache_timeout(3600)); return $maintainer; }
public static function packages(OpenpearMaintainer $maintainer) { $store_key = array('charges_maintainer', $maintainer->id()); if (Store::has($store_key, self::CACHE_TIMEOUT)) { $packages = Store::get($store_key); } else { try { $packages = array(); $charges = C(OpenpearCharge)->find_all(Q::eq('maintainer_id', $maintainer->id())); foreach ($charges as $charge) { $packages[] = $charge->package(); } } catch (Exception $e) { $packages = array(); } Store::set($store_key, $packages, self::CACHE_TIMEOUT); } return $packages; }
public function getWeeklyChart($type = "artist", $from = null, $to = null) { $r = Store::get(); if ($from && $to) { $key = "user:"******":weeklychart:" . $type . ":" . $from . ":" . $to; $chart = $r->get($key); if (!$chart) { $args = array("method" => "user.getweekly" . $type . "chart", "from" => $from, "to" => $to, "user" => $this->name); $chart = API::request($args); if ($chart) { $r->set($key, $chart); } } } else { $key = "user:"******":weeklychart:" . $type . ":latest"; $chart = $r->get($key); if (!$chart) { $args = array("method" => "user.getweekly" . $type . "chart", "user" => $this->name); $chart = API::request($args); if ($chart) { $r->set($key, $chart); $r->expire($key, $this->expires); } } } if ($chart) { $chart = json_decode($chart); $var = "weekly" . $type . "chart"; return $chart->{$var}->{$type}; } else { return null; } }
public function get($resource, $formatCurrency = false) { return $formatCurrency ? $this->formatCurrency(parent::get($resource)) : parent::get($resource); }
function getBalance($user, $params) { $balance = Store::get(Store::META, $user, 'moneys'); restReturn($balance ? 0 + $balance : 0); }
<?php require_once 'FirePHPCore/fb.php'; ob_start(); header("Content-Type: " . ($_SERVER["CONTENT_TYPE"] == 'application/json' ? 'application/json' : 'text/plain')); $store = new Store(); switch ($_SERVER["REQUEST_METHOD"]) { case "GET": echo $store->get(); } class Store { private $jsonArray = array("identifier" => "id", "label" => "id"); private $totalCount = 1000; private $str = "abcd efgh ijkl mnop qrst uvwx yz12 3456 7890"; function __construct() { if (array_key_exists('totalsize', $_REQUEST)) { $this->totalCount = $_REQUEST['totalsize']; } $this->jsonArray['numRows'] = $this->totalCount; } public function get() { return json_encode($this->packup($this->getItems())); } //Private ------------------------------------------------------------------ private function randomText($index) { $len = rand(1, 200); $sb = array();
/** * 存储全局的通信地址 * @param string $address * @todo 用锁机制等保证数据完整性 */ protected function registerAddress($address) { \Man\Core\Lib\Mutex::get(); $key = 'GLOBAL_GATEWAY_ADDRESS'; $addresses_list = Store::get($key); if (empty($addresses_list)) { $addresses_list = array(); } $addresses_list[$address] = $address; Store::set($key, $addresses_list); \Man\Core\Lib\Mutex::release(); }
/** * Tears the given string into its smalest possible parts and rebuilds it * so it will fit nicely into the markup generated by Xiphe\HTML * * @param string $str the string that needs cleaning * * @return string the cleaned string. */ public static function getStrong($str) { /* * Split the content by html tags. */ $tree = preg_split('/(<[^!]?[^>]+>(<![^>]+>)?)/', $str, -1, PREG_SPLIT_OFFSET_CAPTURE | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); /* * Initiate variables. */ $r = array(); $line = ''; $isInline = true; $oneLine = array(); $lastWasTag = false; /* * Loop throu the tree. */ foreach ($tree as $k => $elm) { /* * Check what kind of element this is. */ $info; switch (self::_getTreeElm($elm[0], $info)) { case 'start': /* * It's a starting tag */ $add = new Tag($info[1], array(self::parseAttrs($info[2])), array('generate', $info[3] == '/>' ? 'selfQlose' : 'doNotSelfQlose', 'start', in_array($info[1], TagInfo::$inlineTags) ? 'inline' : null)); break; case 'end': /* * It is a closing tag */ $add = Store::get(); break; case 'comment': case 'content': default: /* * It's something else */ $add = $elm[0]; break; } /* * Add the current content to the output. */ self::_toLine($add, $r, $line, $isInline, $oneLine, $lastWasTag); } /* * Check if there is still content in the current line * and add it to the return array. */ if (strlen($line)) { $r[] = $line; } /* * implode the return array using line breaks and return the string. */ return implode(Generator::getLineBreak(), $r) . Generator::getLineBreak(); }
/** * 获取用户的网关地址 * @param int $uid */ public static function getAddressByUid($uid) { return Store::get($uid); }
/** * ????? * @const string $svn_url リポジトリのURL */ public function source_browse($package_name, $path = '') { if (empty($path)) { $this->redirect_method('source_browse', $package_name, '/trunk'); } // TODO 仕様の確認 // TODO SVNとの連携 $package = C(OpenpearPackage)->find_get(Q::eq('name', $package_name)); $path = rtrim(ltrim($path, ' /.'), '/'); $local_root = File::absolute(OpenpearConfig::svn_root(), $package->name()); $repo_path = File::absolute($local_root, $path); $info = Subversion::cmd('info', array($repo_path)); if ($info['kind'] === 'dir') { $this->vars('tree', self::format_tree(Subversion::cmd('list', array($info['url']), array('revision' => $this->in_vars('rev', 'HEAD'))))); } else { if ($info['kind'] === 'file') { $this->put_block('package/source_viewfile.html'); $p = explode('.', $info['path']); $ext = array_pop($p); if (in_array($ext, $this->allowed_ext)) { $source = Subversion::cmd('cat', array($info['url']), array('revision' => $this->in_vars('rev', 'HEAD'))); $this->vars('code', $source); try { $cache_key = array('syntax_highlight', md5($source)); if (Store::has($cache_key)) { $this->vars('code', Store::get($cache_key)); } else { include_once 'geshi/geshi.php'; $geshi = new Geshi($source, $ext); $code = $geshi->parse_code(); Store::set($cache_key, $code); $this->vars('code', $code); } $this->vars('geshi', true); } catch (Exception $e) { Log::debug($e); $this->vars('geshi', false); } } } else { $this->redirect_by_map('package', $package_name); } } $this->vars('path', $path); $this->vars('info', self::format_info($info)); $this->vars('package', $package); $this->vars('real_url', File::absolute(OpenpearConfig::svn_url(), implode('/', array($package->name(), $path)))); $this->vars('externals', Subversion::cmd('propget', array('svn:externals', $info['url']))); $this->add_vars_other_tree($package_name); }
/** * ファイルから生成する * @param string $filename テンプレートファイルパス * @param string $template_name 対象となるテンプレート名 * @return string */ public function read($filename = null, $template_name = null) { if (!empty($filename)) { $this->filename($filename); } $this->selected_template = $template_name; $cfilename = $this->filename() . $this->selected_template; if (!self::$is_cache || !Store::has($cfilename, true)) { if (strpos($filename, '://') === false) { $src = $this->parse(File::read($this->filename())); } else { if (empty($this->media_url)) { $this->media_url($this->filename()); } $src = $this->parse(Http::read($this->filename())); } if (self::$is_cache) { Store::set($cfilename, $src); } } else { $src = Store::get($cfilename); } $src = $this->html_reform($this->exec($src)); $this->call_module('after_read_template', $src, $this); return $this->replace_ptag($src); }
/** * xml定義からhandlerを処理する * @param string $file アプリケーションXMLのファイルパス */ public static final function load($file = null) { if (!isset($file)) { $file = App::mode() . App::called_filename(); } if (!self::$is_app_cache || !Store::has($file)) { $parse_app = self::parse_app($file, false); if (self::$is_app_cache) { Store::set($file, $parse_app); } } if (self::$is_app_cache) { $parse_app = Store::get($file); } if (empty($parse_app['apps'])) { throw new RuntimeException('undef app'); } $app_result = null; $in_app = $match_handle = false; $app_index = 0; try { foreach ($parse_app['apps'] as $app) { switch ($app['type']) { case 'handle': $self = new self('_inc_session_=false'); foreach ($app['modules'] as $module) { $self->add_module(self::import_instance($module)); } if ($self->has_module('flow_handle_begin')) { $self->call_module('flow_handle_begin', $self); } try { if ($self->handler($app['maps'], $app_index++)->is_pattern()) { $self->cp(self::execute_var($app['vars'])); $src = $self->read(); if ($self->has_module('flow_handle_end')) { $self->call_module('flow_handle_end', $src, $self); } print $src; $in_app = true; $match_handle = true; if (!$parse_app["handler_multiple"]) { exit; } } } catch (Exception $e) { Log::warn($e); if (isset($app['on_error']['status'])) { Http::status_header((int) $app['on_error']['status']); } if (isset($app['on_error']['redirect'])) { $this->save_exception($e); $this->redirect($app['on_error']['redirect']); } else { if (isset($app['on_error']['template'])) { if (!$e instanceof Exceptions) { Exceptions::add($e); } $self->output($app['on_error']['template']); } else { throw $e; } } } break; case 'invoke': $class_name = isset($app['class']) ? Lib::import($app['class']) : get_class($app_result); $ref_class = new ReflectionClass($class_name); foreach ($app['methods'] as $method) { $invoke_class = $ref_class->getMethod($method['method'])->isStatic() ? $class_name : (isset($app['class']) ? new $class_name() : $app_result); $args = array(); foreach ($method['args'] as $arg) { if ($arg['type'] === 'result') { $args[] =& $app_result; } else { $args[] = $arg['value']; } } if (is_object($invoke_class)) { foreach ($app['modules'] as $module) { $invoke_class->add_module(self::import_instance($module)); } } $app_result = call_user_func_array(array($invoke_class, $method['method']), $args); $in_app = true; } break; } } if (!$match_handle) { Log::debug("nomatch"); if ($parse_app["nomatch_redirect"] !== null) { Http::redirect(App::url($parse_app["nomatch_redirect"])); } if ($parse_app["nomatch_template"] !== null) { Http::status_header(404); $self = new self(); $self->output($parse_app["nomatch_template"]); } } if (!$in_app) { Http::status_header(404); } } catch (Exception $e) { if (!$e instanceof Exceptions) { Exceptions::add($e); } } exit; }
$product_amount = $earned_currency_order['product_amount']; // If the order is settled, the developer will receive this // amount of credits as payment. $credits_amount = $earned_currency_order['credits_amount']; // We're giving out our virtual currency for all offers $product_name = $GLOBALS['catalog']['1a']['item_name']; } else { $request_item = $order_details['items'][0]; $sku = $GLOBALS['catalog'][$request_item['item_id']]; $product_amount = $sku['item_quantity']; $product_name = $sku['item_name']; $credits_amount = $request_item['price'] * $GLOBALS['payrate']; } $oldBalance = Store::get(Store::META, $order_details['receiver'], $product_name); Store::set(Store::META, $order_details['receiver'], $product_name, $oldBalance + $product_amount); Store::set(Store::META, 'ourCut', 'creds', Store::get(Store::META, 'ourCut', 'creds') + $credits_amount); $next_order_status = 'settled'; // Construct response. $response = array('content' => array('status' => $next_order_status, 'order_id' => $order_details['order_id']), 'method' => $request_type); // Response must be JSON encoded. $response = json_encode($response); } else { if ($current_order_status == 'disputed') { // 1. Track disputed item orders. // 2. Investigate user's dispute and resolve by settling or refunding the order. // 3. Update the order status asychronously using Graph API. } else { if ($current_order_status == 'refunded') { // Track refunded item orders initiated by Facebook. No need to respond. } else { // Track other order statuses.