public function testApiDelete() { $this->reset(); $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['QUERY_STRING'] = 'foo'; $_POST['deletetoken'] = 'bar'; $request = new request(); $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call'); $this->assertEquals('delete', $request->getOperation()); $this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('bar', $request->getParam('deletetoken')); }
/** * constructor * * initializes and runs ZeroBin * * @access public * @return void */ public function __construct() { if (version_compare(PHP_VERSION, '5.2.6') < 0) { throw new Exception(i18n::_('ZeroBin requires php 5.2.6 or above to work. Sorry.'), 1); } // load config from ini file $this->_init(); switch ($this->_request->getOperation()) { case 'create': $this->_create(); break; case 'delete': $this->_delete($this->_request->getParam('pasteid'), $this->_request->getParam('deletetoken')); break; case 'read': $this->_read($this->_request->getParam('pasteid')); break; case 'jsonld': $this->_jsonld($this->_request->getParam('jsonld')); return; } // output JSON or HTML if ($this->_request->isJsonApiCall()) { header('Content-type: application/json'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); header('Access-Control-Allow-Headers: X-Requested-With, Content-Type'); echo $this->_json; } else { $this->_view(); } }
/** * constructor * * initializes and runs PrivateBin * * @access public * @throws Exception * @return void */ public function __construct() { if (version_compare(PHP_VERSION, '5.3.0') < 0) { throw new Exception(I18n::_('PrivateBin requires php 5.3.0 or above to work. Sorry.'), 1); } if (strlen(PATH) < 0 && substr(PATH, -1) !== DIRECTORY_SEPARATOR) { throw new Exception(I18n::_('PrivateBin requires the PATH to end in a "%s". Please update the PATH in your index.php.', DIRECTORY_SEPARATOR), 5); } // load config from ini file, initialize required classes $this->_init(); switch ($this->_request->getOperation()) { case 'create': $this->_create(); break; case 'delete': $this->_delete($this->_request->getParam('pasteid'), $this->_request->getParam('deletetoken')); break; case 'read': $this->_read($this->_request->getParam('pasteid')); break; case 'jsonld': $this->_jsonld($this->_request->getParam('jsonld')); return; } // output JSON or HTML if ($this->_request->isJsonApiCall()) { header('Content-type: ' . Request::MIME_JSON); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); header('Access-Control-Allow-Headers: X-Requested-With, Content-Type'); echo $this->_json; } else { $this->_view(); } }