/** * @covers SysInfo\Linux\Memory::__construct * @covers SysInfo\Linux\Memory::getTotal * @covers SysInfo\Linux\Memory::getFree * @covers SysInfo\Linux\Memory::getUsed */ public function testMemoryWithSystemData() { $memory = new Memory(); $this->assertInternalType('int', $memory->getTotal()); $this->assertinternalType('int', $memory->getFree()); $this->assertinternalType('int', $memory->getUsed()); }
/** * @covers {className}::{origMethodName} * @todo Implement testGetByUsername(). */ public function testGetByUsername() { $user = new TestUser(1, 'joe2083'); $this->object->add($user); $this->assertEquals($user, $this->object->getByUsername('joe2083')); $this->setExpectedException('\\Fwk\\Security\\Exceptions\\UserNotFound'); $this->assertEquals($user, $this->object->getByUsername('Joe2083', false)); }
/** * @param string $key */ public function remove($key) { // also remove it from $_SESSION to prevent re-setting the old value during the merge if (isset($_SESSION[$key])) { unset($_SESSION[$key]); } parent::remove($key); }
public function __construct($level = DEBUG, $dest = 'tiimber.log') { $this->dest = $det; $this->setBaseLevel($level); Memory::events()->on(LOG, function (string $level, string $message) { if ($this->isLoggable($level)) { $this->log($message); } }); }
private function getHelper() { $helpers = []; foreach (Memory::get(HELPER) as $namespace => $helper) { $pieces = explode('\\', $namespace); $classname = end($pieces); $helpers[strtolower($classname)] = function ($text) use($helper) { return $helper->render($text); }; } return $helpers; }
/** * ループスタート([) */ protected function commandLoopStart() { $c = $this->Memory->current(); if ($c != 0) { return null; } $count = 0; $length = mb_strlen($this->command); for ($i = $this->position; $i < $length; $i++) { if ($this->command[$i] == '[') { $count++; } elseif ($this->command[$i] == ']') { $count--; if ($count == 0) { $this->position = $i; break; } } } }
public function addHeader(string $key, $value) { $headers = Memory::get(HTTP)->get(HEADER); $headers[$key] = $value; Memory::get(HTTP)->set(HEADER, $headers); }
<?php include "../common.php"; include_once 'includes/headers.php'; include_once 'classes/memory.class.php'; include_once 'classes/user.class.php'; include_once $config['SiteClassPath'] . "class.user.register.php"; $ObjUserRegister = new User_Register(); $ObjMemory = new Memory(); $ObjUser = new User(); //http://stackoverflow.com/questions/15485354/angular-http-post-to-php-and-undefined $postdata = file_get_contents("php://input"); $response = array(); if (isset($postdata)) { $request = json_decode($postdata); $facebook_id = $request->facebook_id; $first_name = $request->first_name; $last_name = $request->last_name; $username = $request->username; $birthday = $request->birthday; $email = $request->email; $gender = $request->gender; if ($email && $facebook_id) { // check if user in db => login if (mysql_num_rows($ObjUser->check_facebook_user($facebook_id)) > 0) { $user = mysql_fetch_array($ObjUser->check_facebook_user($facebook_id)); //Random Image $memory = mysql_fetch_array($ObjMemory->getRandMemory($user['id'])); $base_url = "http://the-memories.com/memoryphoto/"; $message = $memory ? $base_url . $memory['MemoryPhoto'] : null; $success = true;
<?php error_reporting(E_ALL); ini_set("display_errors", 1); require_once 'Class/Memory.php'; if (isset($_REQUEST['action']) && isset($_REQUEST['task']) && isset($_REQUEST['workerId'])) { $action = $_REQUEST['action']; //$role = $_REQUEST['role']; $task = $_REQUEST['task']; $workerId = $_REQUEST['workerId']; $nowMemory = new Memory($workerId, $task); switch ($action) { case "postMemory": $memoryId = $nowMemory->postMemory($_REQUEST['memoryLine']); echo $memoryId; break; case "fetchNewMemory": $lastMemoryId = $_REQUEST['lastMemoryId']; $newMemoryArray = $nowMemory->fetchNewMemory($lastMemoryId); echo json_encode($newMemoryArray); break; /* case "fetchNewChatRequester": $lastChatId = $_REQUEST['lastChatId']; $newChatArray = $nowChat->fetchNewChatRequester($lastChatId); echo(json_encode($newChatArray)); break; case "expireChats": $chatTimeoutInSec = $_REQUEST['chatTimeoutInSec']; $lastExpiredChatId = $nowChat->getLastExpiredChatId($chatTimeoutInSec);
public function setCacheFolder($dir) { Memory::set(FOLDER)->set(CACHE, $dir); }
public function visitMemory(Memory $memory) { echo "hello, " . $memory->getName() . "\n"; }
public function emit($event, $name, $render, $args) { Memory::events()->emit($event, ['event' => $name, 'renderer' => $render, 'parameters' => $args]); }
function testCache() { $cache = new Memory(); $users = ['Masoud', 'Alireza']; $cache->write('users', $users); $this->assertCount(1, $cache->stats()); $this->assertTrue($cache->contains('users')); $this->assertEquals($users, $cache->read('users')); $this->assertFalse($cache->expired('users', 1)); $i = 0; $posts = ['Post 1', 'Post 2']; for ($j = 0; $j < 10; $j++) { $result = $cache->remember('posts', function () use(&$i, $posts) { $i++; return $posts; }, 10); } $this->assertEquals(1, $i); $this->assertEquals($posts, $result); $this->assertEquals($posts, $cache->read('posts')); $this->assertCount(2, $cache->stats()); $cache->delete('users'); $this->assertFalse($cache->contains('users')); $this->assertTrue($cache->contains('posts')); $cache->deleteAll(); $this->assertCount(0, $cache->stats()); }
} // Access-Control headers are received during OPTIONS requests if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) { header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); } if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) { header("Access-Control-Allow-Headers: \n\t\t\t{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); } exit(0); } include_once 'classes/user.class.php'; include_once 'classes/simpleimage.class.php'; include_once 'classes/memory.class.php'; $ObjUser = new User(); $ObjMemory = new Memory(); if (isset($_POST["userId"]) && $_POST["memorydate"]) { $userId = $_POST["userId"]; $memorydate = $_POST["memorydate"]; $desc = $_POST["description"]; $fileKey = 'file'; /** * You would add more validation, checking image type or user rights. **/ if (!isset($_FILES[$fileKey]) || !is_uploaded_file($_FILES[$fileKey]['tmp_name'])) { $error = 'Invalid Upload'; } if (!$error && $_FILES[$fileKey]['size'] > 2 * 1024 * 1024) { $error = 'Please upload only files smaller than 2Mb!'; } if (!$error && !($size = @getimagesize($_FILES[$fileKey]['tmp_name']))) {
public function testWriteln() { $output = new Memory(); $output->writeln('foobar'); $this->assertEquals(array('foobar' . PHP_EOL), $output->getMessages()); }
/** * Sum all Child Transactions related to one parent * * @param string $id is a long specifying a new transaction * * @return double sum value */ public function getSumOfChildren($id) { $transactions = $this->memory->fetchAllByAttribute('parent_id', $id, 'amount'); return array_sum($transactions); }
protected function procAssignment(Token $token) { $this->debug(__METHOD__, __LINE__, "identifier: {$token->getValue()}"); // Validate the leftside if ($token->getType() != TokenType::IDENTIFIER) { throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment identifier: '{$token->getValue()}'", __FILE__, __LINE__); } $name = $token->getValue(); $token = $this->getToken(); // Validate the operator switch ($token->getType()) { case TokenType::SYMBOL: switch ($token->getValue()) { case ';': if (!$this->memory->hasVar($name)) { throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($name) + 1, "Unknown identifier: '{$name}'", __FILE__, __LINE__); } // Do nothing :\ return; break; case '=': // allow = break; case '++': case '--': // allow ++ and -- break; default: throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment operator: '{$token->getValue()}'", __FILE__, __LINE__); } break; default: throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment operator: '{$token->getValue()}'", __FILE__, __LINE__); } $operator = $token->getValue(); // Evaluate the rightside $type = $this->evalExp($value); // Perform action switch ($operator) { case '=': $this->memory->setVar($name, $value, $type); break; case '++': // number only // number only case '--': if (!$this->memory->hasVar($name)) { throw new SyntaxException($token->getLine(), $token->getColumn(), "Unknown identifier: '{$name}'", __FILE__, __LINE__); } $value = $this->memory->getVar($name); if ($operator == '++') { $newval = intval($value + 1); } else { $newval = intval($value - 1); } $this->memory->setVar($name, $newval, $type); break; default: throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($operator) + 1, "Unknown operator: '{$operator}'", __FILE__, __LINE__); break; } }
public function testAllocated() { $this->assertInstanceOf("\\BT\\BinaryDigit", $this->object->allocated()); $this->assertInstanceOf("\\BT\\BinaryDigit", $this->object->allocated()); }
} /* Templating class * Important! It must be called before Lang. ------------------------------------------------------------------------ */ $view = new View($loc->path('templates')); // baseurl for all templates $view->set('baseurl', $loc->url('')); /* Stop here for services ------------------------------------------------------------------------ */ $reg_srv = array('service.php'); if (in_array(pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_BASENAME), $reg_srv)) { return; } /* Memory ------------------------------------------------------------------------ */ $mem = new Memory(); /* Favorite icon ------------------------------------------------------------------------ */ $view->set('icons', $cfg->val('icons') ? $cfg->val('icons') : array()); /* Languages support ------------------------------------------------------------------------ */ $lang = new Lang(); if ($cfg->val('LANGUAGES')) { $lang->loadConfig($cfg->val('LANGUAGES')); require 'language.php'; } else { $mem->destroy('langdir'); $view->set('multilang', false); } // by default we always store templates under `ru/` // it won't override if already set smth different.
public function close() { $_SESSION = array_merge($_SESSION, $this->data); session_write_close(); parent::close(); }
public function setPort(int $port) { Memory::set(HTTP)->set(PORT, $port); }