Exemplo n.º 1
0
 /**
  * Clears the debug and run stacks as well as resetting the list of run
  * migrations.
  */
 public function reset()
 {
     $this->runStack = array();
     $this->debugStack = array();
     //Load the list of already run migrations
     $this->oldMigrations = $this->storage->getPast();
 }
Exemplo n.º 2
0
 /**
  * Validate a token.
  *
  * Tokens should be deleted if they are generated as one-time tokens
  * with a unique ID each time.  If the are per-session, then they should be
  * generated with the same unique ID and not deleted when validated here.
  *
  * @param string  $token       Token to validate.
  * @param boolean $delete      Whether to delete the token if valid.
  * @param boolean $checkExpire Whether to check for token expiry.
  *
  * @return boolean
  */
 public function validate($token, $delete = true, $checkExpire = true)
 {
     if (!$token) {
         return false;
     }
     list($id, $hash, $timestamp) = $this->tokenGenerator->decode($token);
     $decoded = array('id' => $id, 'time' => $timestamp);
     // Garbage collect the session.
     $this->tokenGenerator->garbageCollection();
     // Check if token ID exists first.
     $stored = $this->storage->get($decoded['id']);
     if (!$stored) {
         return false;
     }
     // Check if the token has been tampered with.
     $duplicateToken = $this->tokenGenerator->generate($decoded['id'], $decoded['time'])->getToken();
     if ($stored['token'] !== $duplicateToken) {
         $this->storage->delete($decoded['id']);
         return false;
     }
     // Check if token has expired.
     if ($checkExpire) {
         $timeDiff = (int) $decoded['time'] + $this->tokenGenerator->getMaxLifetime() - time();
         if ($timeDiff < 0) {
             $this->storage->delete($decoded['id']);
             return false;
         }
     }
     // All checked out, delete the token and return true.
     if ($delete) {
         $this->storage->delete($decoded['id']);
     }
     return true;
 }
Exemplo n.º 3
0
 function __construct(StorageInterface $storage)
 {
     $this->_basketManager = new BasketManager();
     $this->_basketManager->loadData($storage->getBasketStorage());
     $this->_productManager = new ProductManager();
     $this->_productManager->loadData($storage->getProductStorage());
     $this->_basketItemManager = new BasketItemManager();
     $this->_basketItemManager->loadData($storage->getBasketItemStorage());
 }
Exemplo n.º 4
0
 public function listen()
 {
     $ip = $this->getIp();
     if (is_null($ip)) {
         throw new Exceptions\WithoutIpException();
     }
     if ($this->storage->exists($ip)) {
         throw new Exceptions\BlockedIpException();
     }
 }
Exemplo n.º 5
0
 /**
  * @return array
  */
 public function report()
 {
     if ($this->_storage instanceof RWMutexAwareInterface) {
         $this->_storage->RLock();
     }
     $data = $this->_storage->report();
     if ($this->_storage instanceof RWMutexAwareInterface) {
         $this->_storage->RUnlock();
     }
     return $data;
 }
Exemplo n.º 6
0
 /**
  * Given a list of migrations will compile dependencies and run the up method
  * of all needed migrations.
  *
  * @param string|array $migrations
  *
  * @return boolean
  */
 public function up($migrations)
 {
     $migrations = (array) $migrations;
     $this->dc->reset();
     //Add the migration to the DC, if it does not need to be run the list
     //returned will be empty
     foreach ($migrations as $migration) {
         $this->dc->addMigration($migration);
     }
     $toRun = $this->dc->getList();
     //Start running the migrations
     foreach ($toRun as $class => $migration) {
         $result = $this->runMigration($migration);
         //If this is a bad migration then start the rollback process.
         if ($result == Migration::BAD) {
             return false;
         }
         // All is good so log the migration as having run
         $this->storage->add($class);
     }
     return true;
 }
Exemplo n.º 7
0
 /**
  * Send task over RPC to worker
  * Mark task as in progress nad worker as busy
  * @param  Task   $task
  * @param  Worker $worker
  * @return void
  * @author Andraz <*****@*****.**>
  */
 public function sendTaskToWorker(Task $task, Worker $worker)
 {
     $client = $this->newRpcClient($worker->getHost(), $worker->getport());
     $parameters = [$worker->getId(), $task->getId(), $task->getParameters()];
     $task->setStatus('in_progress');
     $this->storage->saveTask($task);
     $worker->setStatus('busy');
     $this->storage->saveWorker($worker);
     $success = $client->notify('run', $parameters);
     if ($success) {
     }
     return $success;
 }
Exemplo n.º 8
0
 public function copy()
 {
     /* @var $new S3File */
     $new = parent::copy();
     ob_start();
     //copy our new one to its own path.
     $newPath = parent::getNiceDir($new->get('path'));
     $this->client->copyObject(array('Bucket' => AMAZON_S3_BUCKET_NAME, 'Key' => $newPath, 'CopySource' => $this->get('bucket') . "/" . $this->get('path'), 'ACL' => 'public-read'));
     $new->set('path', $newPath);
     $new->set('bucket', AMAZON_S3_BUCKET_NAME);
     $new->save();
     ob_end_clean();
     return $new;
 }
Exemplo n.º 9
0
 private function saveNode(Node $node = null)
 {
     if ($node === null) {
         return;
     }
     $this->saveNode($node->rightNode);
     $this->saveNode($node->leftNode);
     if ($node->valueType === 1 && $node->subNode !== null) {
         $node->value = $this->saveNode($node->subNode);
     }
     if ($node->pointer === 0) {
         $node->pointer = $this->storage->add($node->pack());
     } else {
         $this->storage->update($node->pointer, $node->pack());
     }
     return $node->pointer;
 }
Exemplo n.º 10
0
 /**
  * @param NodesProvider $storage
  */
 public function __construct(StorageInterface $storage)
 {
     $node = new Node();
     $node->valueType = 1;
     $data = $node->pack();
     $blockSize = strlen(bin2hex($data)) / 2;
     $storage->setBlockSize($blockSize);
     $storage->lock();
     if ($storage->isEmpty()) {
         $storage->add($data);
     }
     $storage->unlock();
     $this->setStorage($storage);
     $this->setHeadNodePointer(0);
 }
Exemplo n.º 11
0
 /**
  * 启动前调用
  */
 protected function initialize()
 {
     // 初始化桥配置
     if (!is_null($this->bridge)) {
         $this->bridge->initialize($this);
     }
     // 初始化存储接口
     if (!is_null($this->storage)) {
         $this->storage->initialize($this);
     }
     // 设置session id;如果设置了id则不会再生成session文件
     if (!is_null($this->id)) {
         session_id($this->id);
     }
     // 自定义session;name
     if (!is_null($this->name)) {
         session_name($this->name);
     }
 }
Exemplo n.º 12
0
 public static function _handleZipFile($zip_path, $zip_file)
 {
     $za = new ZipArchive();
     $za->open($zip_path);
     for ($i = 0; $i < $za->numFiles; $i++) {
         //look up file info.
         $filename = $za->getNameIndex($i);
         //okay, is it a supported file?
         if (preg_match('/(gcode|stl|obj|amf)$/i', $filename)) {
             $temp_file = tempnam("/tmp", "BQ");
             copy("zip://" . $zip_path . "#" . $filename, $temp_file);
             //format for upload
             $filename = str_replace(" ", "_", $filename);
             $filename = preg_replace("/[^-_.[0-9a-zA-Z]/", "", $filename);
             $path = "assets/" . StorageInterface::getNiceDir($filename);
             //create our file
             $file = Storage::newFile();
             $file->set('parent_id', $zip_file->id);
             $file->set('user_id', User::$me->id);
             $file->upload($temp_file, $path);
         }
     }
     //exit;
 }
Exemplo n.º 13
0
 /**
  * Sets and persists this setting's value overwriting any existing value.
  * 
  * @param mixed $value
  * @throws \Exception If the current user is not allowed to change the value of this setting.
  */
 public function setValue($value)
 {
     return $this->storage->setSettingValue($this, $value);
 }
Exemplo n.º 14
0
 /**
  * Flushes compiler storage
  *
  * @return $this
  */
 public function flush()
 {
     $this->storage->flush();
     return $this;
 }
Exemplo n.º 15
0
 /**
  *
  * @param int $counter            
  */
 public function updateLastRequestCounter($count)
 {
     $this->storage->update(['request_count' => $count]);
 }
Exemplo n.º 16
0
 /**
  * @covers \Packfire\Session\Session::bucket
  */
 public function testBucket2()
 {
     $this->stub->expects($this->once())->method('bucket')->with($this->equalTo('test'))->will($this->returnValue(true));
     $this->assertTrue($this->object->bucket('test'));
 }
Exemplo n.º 17
0
 public function api_devicescanresults()
 {
     //$old_scan_data = json::decode($this->token->get('device_data'));
     $scan_data = json::decode($this->args('scan_data'));
     //var_dump($scan_data);
     if (!empty($_FILES)) {
         // We currently don't want to delete the old data
         //			//delete any old files if we have them.
         //			if (!empty($old_scan_data->camera_files)) {
         //				foreach ($old_scan_data->camera_files AS $id) {
         //					$data_file = Storage::get($id);
         //					$data_file->delete();
         //				}
         //			}
         foreach ($_FILES as $file) {
             if (is_uploaded_file($file['tmp_name'])) {
                 $filename = $file['name'];
                 $filename = str_replace(" ", "_", $filename);
                 $filename = preg_replace("/[^-_.[0-9a-zA-Z]/", "", $filename);
                 $this->ensureGoodFile($file);
                 //okay, we're good.. do it.
                 $data_file = Storage::newFile();
                 $data_file->set('user_id', User::$me->id);
                 $data_file->upload($file['tmp_name'], StorageInterface::getNiceDir($filename));
                 $scan_data->camera_files[] = $data_file->id;
             }
         }
     }
     //var_dump($scan_data);
     //var_dump($_FILES);
     $this->token->set('device_data', json::encode($scan_data));
     $this->token->set('last_seen', date('Y-m-d H:i:s'));
     $this->token->save();
     return True;
 }
Exemplo n.º 18
0
 public function __construct($id = null)
 {
     parent::__construct($id, "s3_files");
 }
Exemplo n.º 19
0
 /**
  * @dataProvider emptyFilenameProvider
  */
 public function testResolveUriWithEmptyFile($filename)
 {
     $this->mapping->expects($this->once())->method('getFileName')->will($this->returnValue($filename));
     $this->factory->expects($this->once())->method('fromName')->with($this->object, 'file_mapping')->will($this->returnValue($this->mapping));
     $this->assertNull($this->storage->resolvePath($this->object, 'file_mapping'));
 }
Exemplo n.º 20
0
Arquivo: Cart.php Projeto: voku/cart
 /**
  * Set the cart identifier, useful if restoring a saved cart
  *
  * @param mixed $identifier The identifier
  */
 public function setIdentifier($identifier)
 {
     $this->store->setIdentifier($identifier);
 }
Exemplo n.º 21
0
<?php

function __autoload($class_name)
{
    require_once "./system/" . $class_name . "/" . $class_name . ".php";
}
function arg($nbr = -1)
{
    $arg = explode('/', $_SERVER['PHP_SELF']);
    if ($nbr == -1) {
        return $arg;
    } else {
        if ($nbr < count($arg)) {
            return $arg[$nbr];
        } else {
            return;
        }
    }
}
$intf = new StorageInterface($config['database']);
$installed = $intf->cmsInstalled();
if ($installed) {
    if (arg(2) === 'install.php') {
        print 'TODO install system';
    } else {
        print $installed;
    }
} else {
    print 'ok';
}
Exemplo n.º 22
0
 public function uploadNice($srcPath, $name, $prefix = "")
 {
     $this->upload($srcPath, $prefix . StorageInterface::getNiceDir($name));
 }
Exemplo n.º 23
0
 public function url()
 {
     $this->assertLoggedIn();
     $this->setTitle("Create Job from URL");
     try {
         //did we get a url?
         $url = $this->args('url');
         if (!$url) {
             throw new Exception("You must pass in the URL parameter!");
         }
         $matches = array();
         if (preg_match("/thingiverse.com\\/thing:([0-9]+)/i", $url, $matches)) {
             $thing_id = $matches[1];
             //echo "found: $thing_id<Br/>";
             // TODO: We need to define a thingiverse api client ID, or get it when the user
             // authenticates it.
             $api = new ThingiverseAPI(THINGIVERSE_API_CLIENT_ID, THINGIVERSE_API_CLIENT_SECRET, User::$me->getThingiverseToken());
             //load thingiverse data.
             $thing = $api->make_call("/things/{$thing_id}");
             $files = $api->make_call("/things/{$thing_id}/files");
             //echo "<pre>";
             //print_r($thing);
             //print_r($files);
             //echo "</pre>";
             //open zip file.
             $zip_path = tempnam("/tmp", "BQ");
             $zip = new ZipArchive();
             if ($zip->open($zip_path, ZIPARCHIVE::CREATE)) {
                 //echo "opened $zip_path<br/>";
                 //pull in all our files.
                 foreach ($files as $row) {
                     if (preg_match("/\\.(stl|obj|amf|gcode)\$/i", $row->name)) {
                         $data = Utility::downloadUrl($row->public_url);
                         //echo "downloaded " . $data['realname'] . " to " . $data['localpath'] . "<br/>";
                         $zip->addFile($data['localpath'], $data['realname']);
                     }
                 }
                 $zip->close();
                 //create zip name.
                 $filename = basename($thing->name . ".zip");
                 $filename = str_replace(" ", "_", $filename);
                 $filename = preg_replace("/[^-_.[0-9a-zA-Z]/", "", $filename);
                 $path = "assets/" . StorageInterface::getNiceDir($filename);
                 //okay, upload it and handle it.
                 $file = Storage::newFile();
                 $file->set('user_id', User::$me->id);
                 $file->set('source_url', $url);
                 //echo "uploading $zip_path to $path<br/>";
                 $file->upload($zip_path, $path);
                 FileUploadHandler::_handleZipFile($zip_path, $file);
                 $this->forwardToUrl("/job/create/file:{$file->id}");
             } else {
                 throw new Exception("Unable to open zip {$zip_path} for writing.");
             }
         } else {
             $data = Utility::downloadUrl($url);
             //does it match?
             if (!preg_match("/\\.(stl|obj|amf|gcode|zip)\$/i", $data['realname'])) {
                 throw new Exception("The file <a href=\"" . $url . "\">{$data['realname']}</a> is not valid for printing.");
             }
             $file = Storage::newFile();
             $file->set('user_id', User::$me->id);
             $file->set('source_url', $url);
             $file->upload($data['localpath'], StorageInterface::getNiceDir($data['realname']));
             //is it a zip file?  do some magic on it.
             if (!preg_match("/\\.zip\$/i", $data['realname'])) {
                 FileUploadHandler::_handleZipFile($data['localpath'], $file);
             }
             Activity::log("uploaded a new file called " . $file->getLink() . ".");
             //send us to step 2.
             $this->forwardToUrl("/job/create/file:{$file->id}");
         }
     } catch (Exception $e) {
         $this->set('megaerror', $e->getMessage());
     }
 }
Exemplo n.º 24
0
 /**
  * Return all identifiers from storage
  * @return mixed
  */
 public function getOnlineUsers()
 {
     return $this->onlineUsers->getOnlineUsers();
 }
Exemplo n.º 25
0
 /**
  * Registers a storage container.
  * 
  * @param \WordPress\Data\StorageInterface $storage
  * 
  * @return \WordPress\Data\Manager
  */
 public function addStorage(StorageInterface $storage)
 {
     $this->storage[$storage->getName()] = $storage;
     return $this;
 }
Exemplo n.º 26
0
Arquivo: Item.php Projeto: voku/cart
 /**
  * Removes the current item from the cart
  *
  * @return void
  */
 public function remove()
 {
     $this->store->remove($this->identifier);
 }
Exemplo n.º 27
0
 /**
  * Clears the the storage content
  */
 public function clear()
 {
     $this->storage->clear();
 }