Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A simple class that defines a URL.
- */
- @class URL
- protected:
- /**The scheme part of the url: http, https, ftp, etc.*/
- string scheme (rw);
- /**The host of the url: google.com, facebook.com ...*/
- string host (rw);
- /**The port of the url: 80, 90, 8080, etc.*/
- integer port (rw);
- /**The user for the url: kylekirby, etc.*/
- string user (rw);
- /**The password for the url: p@$$w0|2d*/
- string password (rw);
- /**The path for the url: /index.php*/
- string path (rw);
- /**The query for the url, sans ?: page=root&id=12*/
- string query (rw);
- /**The fragment for the url, sans #: myInlineAnchor*/
- string fragment (rw);
- /**A stored id for the cache.*/
- string cacheId;
- /**The stored cache.*/
- string cache;
- /**
- * @return string A newly built cache ID for the
- * current configuration.
- */
- - (string) getCurrentCacheId;
- <?
- return md5(
- $this->getScheme() .
- $this->getHost() .
- $this->getPort() .
- $this->getUser() .
- $this->getPassword() .
- $this->getPath() .
- $this->getQuery() .
- $this->getFragment()
- );
- ?>
- /**Builds the URL based on the current configuration.*/
- - (void) build;
- <?
- $url = $this->getScheme() . '://';
- if($user = $this->getUser()){
- $url .= $user;
- if($pasword = $this->getPassword()){
- $url .= ':' . $pasword;
- }
- $url .= '@';
- }
- $url .= $this->getHost();
- if($port = $this->getPort()){
- $url .= ':' . $port;
- }
- $url .= '/' . ltrim($this->getPath(),'/');
- if($query = $this->getQuery()){
- $url .= '?' . $query;
- }
- if($fragment = $this->getFragment()){
- $url .= '#' . $fragment;
- }
- $this->_setCache(
- $url
- );
- $this->_setCacheId(
- $this->_getCurrentCacheId()
- );
- ?>
- public:
- - (void) __construct: (string)url = null;
- <?
- if($url){
- $this->parse($url);
- }
- ?>
- /**
- * Parse a URL and populate the parts
- * into this class.
- */
- - (void) parse: (string)url;
- <?
- $parts = parse_url($url);
- $this->setScheme($parts['scheme']);
- $this->setHost($parts['host']);
- $this->setPort($parts['port']);
- $this->setUser($parts['user']);
- $this->setPassword($parts['pass']);
- $this->setPath($parts['path']);
- $this->setQuery($parts['query']);
- $this->setFragment($parts['fragment']);
- $this->_setCache(null);
- ?>
- /**
- * @return string The built URL based on the
- * current configuration.
- */
- - (string) get;
- <?
- if(!$this->_getCache() || $this->_getCurrentCacheId() !== $this->_getCacheId()){
- $this->_build();
- }
- return $this->_getCache();
- ?>
- - (string) __toString;
- <?
- return $this->get();
- ?>
- @end
- /**
- * An interface that defines how a stream
- * should behave.
- */
- @interface Stream
- public:
- /**Read a specified amount of bytes*/
- - (string) readBytes: (integer)bytes;
- /**Read a single character.*/
- - (string) readChar;
- /**Read an entire line.*/
- - (string) readLine;
- /**Read the entire stream, until EOF.*/
- - (string) readAll;
- /**Rewind the internal pointer.*/
- - (boolean) rewind;
- /**Write a chunk of data to the stream.*/
- - (integer) write: (string)content;
- /**Offset the internal pointer by $offset.*/
- - (integer) seek: (integer)offset;
- /**Get information about the stream.*/
- - (array) stat;
- @end
- /**
- * An abstract wrapper for built in PHP
- * stream resources. Simply implement
- * the get resource method.
- */
- @abstract StreamWrapper implements Stream
- public:
- - (resource) getResource;
- - (string) readBytes: (integer)bytes;
- <?
- return fread($this->getResource(),$bytes);
- ?>
- - (string) readChar;
- <?
- return fgetc($this->getResource());
- ?>
- - (string) readLine;
- <?
- return fgets($this->getResource());
- ?>
- - (string) readAll;
- <?
- ob_start();
- fpassthru($this->getResource());
- return ob_get_clean();
- ?>
- - (boolean) rewind;
- <?
- return rewind($this->getResource());
- ?>
- - (integer) seek:(integer)offset;
- <?
- return fseek($this->getResource(),$offset);
- ?>
- - (integer) write: (string)content;
- <?
- fwrite($this->getResource(),$content);
- ?>
- - (array) stat;
- <?
- return fstat($this->getResource());
- ?>
- @end
- /**
- * A stream for temporary data.
- */
- @class TempStream extends StreamWrapper
- protected:
- resource resource (ro) = {fopen('php://temp','rw')};
- @end
- @abstract Request
- protected:
- URL url (rw);
- Stream post (rw);
- public:
- - (void) execute;
- @end
- @class MBloxRequest
- protected:
- string partnerName (rw);
- string partnerPassword (rw);
- string message (rw);
- string senderId (rw);
- string operator (rw);
- string subscriberNumber (rw);
- string requestUrl (rw);
- public:
- - (string) queue;
- <?
- // yeah
- ?>
- @end
- ==== Creates ====
- <?php
- /**
- * A simple class that defines a URL.
- */
- class URL {
- /**
- * The scheme part of the url: http, https, ftp, etc.
- *
- * @param string scheme
- */
- protected $_scheme;
- /**
- * The host of the url: google.com, facebook.com ...
- *
- * @param string host
- */
- protected $_host;
- /**
- * The port of the url: 80, 90, 8080, etc.
- *
- * @param integer port
- */
- protected $_port;
- /**
- * The user for the url: kylekirby, etc.
- *
- * @param string user
- */
- protected $_user;
- /**
- * The password for the url: p@$$w0|2d
- *
- * @param string password
- */
- protected $_password;
- /**
- * The path for the url: /index.php
- *
- * @param string path
- */
- protected $_path;
- /**
- * The query for the url, sans ?: page=root&id=12
- *
- * @param string query
- */
- protected $_query;
- /**
- * The fragment for the url, sans #: myInlineAnchor
- *
- * @param string fragment
- */
- protected $_fragment;
- /**
- * A stored id for the cache.
- *
- * @param string cacheId
- */
- protected $_cacheId;
- /**
- * The stored cache.
- *
- * @param string cache
- */
- protected $_cache;
- /**
- * @uses self::$_scheme
- * @return string scheme
- */
- public function getScheme(){
- return $this->_scheme;
- }
- /**
- * @param string $scheme
- * @uses self::$_scheme
- * @return void
- */
- public function setScheme($scheme){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($scheme) . ' was passed to argument $scheme on method URL::setScheme(); however a string was expected.');
- }
- unset($arguments);
- $this->_scheme = $scheme;
- return $this;
- }
- /**
- * @uses self::$_host
- * @return string host
- */
- public function getHost(){
- return $this->_host;
- }
- /**
- * @param string $host
- * @uses self::$_host
- * @return void
- */
- public function setHost($host){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($host) . ' was passed to argument $host on method URL::setHost(); however a string was expected.');
- }
- unset($arguments);
- $this->_host = $host;
- return $this;
- }
- /**
- * @uses self::$_port
- * @return integer port
- */
- public function getPort(){
- return $this->_port;
- }
- /**
- * @param integer $port
- * @uses self::$_port
- * @return void
- */
- public function setPort($port){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_integer($arguments[0])){
- throw new Exception('An ' . gettype($port) . ' was passed to argument $port on method URL::setPort(); however a integer was expected.');
- }
- unset($arguments);
- $this->_port = $port;
- return $this;
- }
- /**
- * @uses self::$_user
- * @return string user
- */
- public function getUser(){
- return $this->_user;
- }
- /**
- * @param string $user
- * @uses self::$_user
- * @return void
- */
- public function setUser($user){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($user) . ' was passed to argument $user on method URL::setUser(); however a string was expected.');
- }
- unset($arguments);
- $this->_user = $user;
- return $this;
- }
- /**
- * @uses self::$_password
- * @return string password
- */
- public function getPassword(){
- return $this->_password;
- }
- /**
- * @param string $password
- * @uses self::$_password
- * @return void
- */
- public function setPassword($password){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($password) . ' was passed to argument $password on method URL::setPassword(); however a string was expected.');
- }
- unset($arguments);
- $this->_password = $password;
- return $this;
- }
- /**
- * @uses self::$_path
- * @return string path
- */
- public function getPath(){
- return $this->_path;
- }
- /**
- * @param string $path
- * @uses self::$_path
- * @return void
- */
- public function setPath($path){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($path) . ' was passed to argument $path on method URL::setPath(); however a string was expected.');
- }
- unset($arguments);
- $this->_path = $path;
- return $this;
- }
- /**
- * @uses self::$_query
- * @return string query
- */
- public function getQuery(){
- return $this->_query;
- }
- /**
- * @param string $query
- * @uses self::$_query
- * @return void
- */
- public function setQuery($query){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($query) . ' was passed to argument $query on method URL::setQuery(); however a string was expected.');
- }
- unset($arguments);
- $this->_query = $query;
- return $this;
- }
- /**
- * @uses self::$_fragment
- * @return string fragment
- */
- public function getFragment(){
- return $this->_fragment;
- }
- /**
- * @param string $fragment
- * @uses self::$_fragment
- * @return void
- */
- public function setFragment($fragment){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($fragment) . ' was passed to argument $fragment on method URL::setFragment(); however a string was expected.');
- }
- unset($arguments);
- $this->_fragment = $fragment;
- return $this;
- }
- /**
- * @uses self::$_cacheId
- * @return string cacheId
- */
- protected function _getCacheId(){
- return $this->_cacheId;
- }
- /**
- * @param string $cacheId
- * @uses self::$_cacheId
- * @return void
- */
- protected function _setCacheId($cacheId){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($cacheId) . ' was passed to argument $cacheId on method URL::setCacheId(); however a string was expected.');
- }
- unset($arguments);
- $this->_cacheId = $cacheId;
- return $this;
- }
- /**
- * @uses self::$_cache
- * @return string cache
- */
- protected function _getCache(){
- return $this->_cache;
- }
- /**
- * @param string $cache
- * @uses self::$_cache
- * @return void
- */
- protected function _setCache($cache){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($cache) . ' was passed to argument $cache on method URL::setCache(); however a string was expected.');
- }
- unset($arguments);
- $this->_cache = $cache;
- return $this;
- }
- /**
- * @return string A newly built cache ID for the
- * current configuration.
- */
- protected function _getCurrentCacheId(){
- return md5(
- $this->getScheme() .
- $this->getHost() .
- $this->getPort() .
- $this->getUser() .
- $this->getPassword() .
- $this->getPath() .
- $this->getQuery() .
- $this->getFragment()
- );
- }
- /**
- * Builds the URL based on the current configuration.
- *
- * @return void
- */
- protected function _build(){
- $url = $this->getScheme() . '://';
- if($user = $this->getUser()){
- $url .= $user;
- if($pasword = $this->getPassword()){
- $url .= ':' . $pasword;
- }
- $url .= '@';
- }
- $url .= $this->getHost();
- if($port = $this->getPort()){
- $url .= ':' . $port;
- }
- $url .= '/' . ltrim($this->getPath(),'/');
- if($query = $this->getQuery()){
- $url .= '?' . $query;
- }
- if($fragment = $this->getFragment()){
- $url .= '#' . $fragment;
- }
- $this->_setCache(
- $url
- );
- $this->_setCacheId(
- $this->_getCurrentCacheId()
- );
- }
- /**
- * @param string $url
- * @return void
- */
- public function __construct($url = null){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($url) . ' was passed to argument $url on method URL::__construct(); however a string was expected.');
- }
- unset($arguments);
- if($url){
- $this->parse($url);
- }
- }
- /**
- * Parse a URL and populate the parts
- * into this class.
- *
- * @param string $url
- * @return void
- */
- public function parse($url){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($url) . ' was passed to argument $url on method URL::parse(); however a string was expected.');
- }
- unset($arguments);
- $parts = parse_url($url);
- $this->setScheme($parts['scheme']);
- $this->setHost($parts['host']);
- $this->setPort($parts['port']);
- $this->setUser($parts['user']);
- $this->setPassword($parts['pass']);
- $this->setPath($parts['path']);
- $this->setQuery($parts['query']);
- $this->setFragment($parts['fragment']);
- $this->_setCache(null);
- }
- /**
- * @return string The built URL based on the
- * current configuration.
- */
- public function get(){
- if(!$this->_getCache() || $this->_getCurrentCacheId() !== $this->_getCacheId()){
- $this->_build();
- }
- return $this->_getCache();
- }
- /**
- * @return string
- */
- public function __toString(){
- return $this->get();
- }
- }
- /**
- * An interface that defines how a stream
- * should behave.
- */
- interface Stream {
- /**
- * Read a specified amount of bytes
- *
- * @param integer $bytes
- * @return string
- */
- public function readBytes($bytes);
- /**
- * Read a single character.
- *
- * @return string
- */
- public function readChar();
- /**
- * Read an entire line.
- *
- * @return string
- */
- public function readLine();
- /**
- * Read the entire stream, until EOF.
- *
- * @return string
- */
- public function readAll();
- /**
- * Rewind the internal pointer.
- *
- * @return boolean
- */
- public function rewind();
- /**
- * Write a chunk of data to the stream.
- *
- * @param string $content
- * @return integer
- */
- public function write($content);
- /**
- * Offset the internal pointer by $offset.
- *
- * @param integer $offset
- * @return integer
- */
- public function seek($offset);
- /**
- * Get information about the stream.
- *
- * @return array
- */
- public function stat();
- }
- /**
- * An abstract wrapper for built in PHP
- * stream resources. Simply implement
- * the get resource method.
- */
- abstract class StreamWrapper {
- /**
- * @return resource
- */
- public abstract function getResource();
- /**
- * @param integer $bytes
- * @return string
- */
- public function readBytes($bytes){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_integer($arguments[0])){
- throw new Exception('An ' . gettype($bytes) . ' was passed to argument $bytes on method StreamWrapper::readBytes(); however a integer was expected.');
- }
- unset($arguments);
- return fread($this->getResource(),$bytes);
- }
- /**
- * @return string
- */
- public function readChar(){
- return fgetc($this->getResource());
- }
- /**
- * @return string
- */
- public function readLine(){
- return fgets($this->getResource());
- }
- /**
- * @return string
- */
- public function readAll(){
- ob_start();
- fpassthru($this->getResource());
- return ob_get_clean();
- }
- /**
- * @return boolean
- */
- public function rewind(){
- return rewind($this->getResource());
- }
- /**
- * @param integer $offset
- * @return integer
- */
- public function seek($offset){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_integer($arguments[0])){
- throw new Exception('An ' . gettype($offset) . ' was passed to argument $offset on method StreamWrapper::seek(); however a integer was expected.');
- }
- unset($arguments);
- return fseek($this->getResource(),$offset);
- }
- /**
- * @param string $content
- * @return integer
- */
- public function write($content){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($content) . ' was passed to argument $content on method StreamWrapper::write(); however a string was expected.');
- }
- unset($arguments);
- fwrite($this->getResource(),$content);
- }
- /**
- * @return array
- */
- public function stat(){
- return fstat($this->getResource());
- }
- }
- /**
- * A stream for temporary data.
- */
- class TempStream extends StreamWrapper {
- /**
- * @param resource resource
- */
- protected $_resource;
- /**
- * @uses self::$_resource
- * @return resource resource
- */
- public function getResource(){
- if($this->_resource === null){
- $this->_resource = fopen('php://temp','rw');
- }
- return $this->_resource;
- }
- }
- abstract class Request {
- /**
- * @param URL url
- */
- protected $_url;
- /**
- * @param Stream post
- */
- protected $_post;
- /**
- * @uses self::$_url
- * @return URL url
- */
- public function getUrl(){
- return $this->_url;
- }
- /**
- * @param URL $url
- * @uses self::$_url
- * @return void
- */
- public function setUrl(URL $url){
- $this->_url = $url;
- return $this;
- }
- /**
- * @uses self::$_post
- * @return Stream post
- */
- public function getPost(){
- return $this->_post;
- }
- /**
- * @param Stream $post
- * @uses self::$_post
- * @return void
- */
- public function setPost(Stream $post){
- $this->_post = $post;
- return $this;
- }
- /**
- * @return void
- */
- public abstract function execute();
- }
- class MBloxRequest {
- /**
- * @param string partnerName
- */
- protected $_partnerName;
- /**
- * @param string partnerPassword
- */
- protected $_partnerPassword;
- /**
- * @param string message
- */
- protected $_message;
- /**
- * @param string senderId
- */
- protected $_senderId;
- /**
- * @param string operator
- */
- protected $_operator;
- /**
- * @param string subscriberNumber
- */
- protected $_subscriberNumber;
- /**
- * @param string requestUrl
- */
- protected $_requestUrl;
- /**
- * @uses self::$_partnerName
- * @return string partnerName
- */
- public function getPartnerName(){
- return $this->_partnerName;
- }
- /**
- * @param string $partnerName
- * @uses self::$_partnerName
- * @return void
- */
- public function setPartnerName($partnerName){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($partnerName) . ' was passed to argument $partnerName on method MBloxRequest::setPartnerName(); however a string was expected.');
- }
- unset($arguments);
- $this->_partnerName = $partnerName;
- return $this;
- }
- /**
- * @uses self::$_partnerPassword
- * @return string partnerPassword
- */
- public function getPartnerPassword(){
- return $this->_partnerPassword;
- }
- /**
- * @param string $partnerPassword
- * @uses self::$_partnerPassword
- * @return void
- */
- public function setPartnerPassword($partnerPassword){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($partnerPassword) . ' was passed to argument $partnerPassword on method MBloxRequest::setPartnerPassword(); however a string was expected.');
- }
- unset($arguments);
- $this->_partnerPassword = $partnerPassword;
- return $this;
- }
- /**
- * @uses self::$_message
- * @return string message
- */
- public function getMessage(){
- return $this->_message;
- }
- /**
- * @param string $message
- * @uses self::$_message
- * @return void
- */
- public function setMessage($message){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($message) . ' was passed to argument $message on method MBloxRequest::setMessage(); however a string was expected.');
- }
- unset($arguments);
- $this->_message = $message;
- return $this;
- }
- /**
- * @uses self::$_senderId
- * @return string senderId
- */
- public function getSenderId(){
- return $this->_senderId;
- }
- /**
- * @param string $senderId
- * @uses self::$_senderId
- * @return void
- */
- public function setSenderId($senderId){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($senderId) . ' was passed to argument $senderId on method MBloxRequest::setSenderId(); however a string was expected.');
- }
- unset($arguments);
- $this->_senderId = $senderId;
- return $this;
- }
- /**
- * @uses self::$_operator
- * @return string operator
- */
- public function getOperator(){
- return $this->_operator;
- }
- /**
- * @param string $operator
- * @uses self::$_operator
- * @return void
- */
- public function setOperator($operator){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($operator) . ' was passed to argument $operator on method MBloxRequest::setOperator(); however a string was expected.');
- }
- unset($arguments);
- $this->_operator = $operator;
- return $this;
- }
- /**
- * @uses self::$_subscriberNumber
- * @return string subscriberNumber
- */
- public function getSubscriberNumber(){
- return $this->_subscriberNumber;
- }
- /**
- * @param string $subscriberNumber
- * @uses self::$_subscriberNumber
- * @return void
- */
- public function setSubscriberNumber($subscriberNumber){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($subscriberNumber) . ' was passed to argument $subscriberNumber on method MBloxRequest::setSubscriberNumber(); however a string was expected.');
- }
- unset($arguments);
- $this->_subscriberNumber = $subscriberNumber;
- return $this;
- }
- /**
- * @uses self::$_requestUrl
- * @return string requestUrl
- */
- public function getRequestUrl(){
- return $this->_requestUrl;
- }
- /**
- * @param string $requestUrl
- * @uses self::$_requestUrl
- * @return void
- */
- public function setRequestUrl($requestUrl){
- $arguments = func_get_args();
- if(isset($arguments[0]) && !is_string($arguments[0])){
- throw new Exception('An ' . gettype($requestUrl) . ' was passed to argument $requestUrl on method MBloxRequest::setRequestUrl(); however a string was expected.');
- }
- unset($arguments);
- $this->_requestUrl = $requestUrl;
- return $this;
- }
- /**
- * @return string
- */
- public function queue(){
- // yeah
- }
- }
- ?>
Add Comment
Please, Sign In to add comment