<?php <br/> require_once '../app/config.php' ; <br/> require_once 'amfphp/gateway.php' ;
<?php <br/> // <br/> define ( 'ROOT_DIR' , '/var/www/game/' ) ; // <br/> define ( 'LOG_DIR' , ROOT_DIR . 'log/' ) ; // <br/> define ( 'GAME_PLATFORM' , 'development' ) ; // <br/> $paths = array ( <br/> '.' , <br/> ROOT_DIR . 'lib' , <br/> ROOT_DIR . 'app' <br/> ) ; <br/> set_include_path ( implode ( PATH_SEPARATOR , $paths ) ) ;
<?php <?php <br/>abstract class Response<br/> { <br/> protected $error ; <br/> protected $content = array ( ) ; <br/> <br/> public function __construct ( array $content = null ) <br/> { <br/> if ( isset ( $content ) ) { <br/> $this -> content = $content ; <br/> } <br/> } <br/> <br/> public function addContent ( $content ) <br/> { <br/> if ( ! is_array ( $content ) ) { <br/> return false ; <br/> } <br/> foreach ( $content as $name => $data ) { <br/> $this -> content [ $name ] = $data ; <br/> } <br/> } <br/> <br/> public function getData ( ) <br/> { <br/> return array ( <br/> 'error' => $this -> error , <br/> 'response' => $this -> content , <br/> ) ; <br/> } <br/> } <br/> <br/> class ErrorResponse extends Response<br/> { <br/> public function __construct ( array $content = null ) <br/> { <br/> parent :: __construct ( $content ) ; <br/> $this -> error = 1 ; <br/> } <br/> } <br/> <br/> class SuccessResponse extends Response<br/> { <br/> public function __construct ( array $content = null ) <br/> { <br/> parent :: __construct ( $content ) ; <br/> $this -> error = 0 ; <br/> } <br/> }
<?php <?php <br/>abstract class Response<br/> { <br/> protected $error ; <br/> protected $content = array ( ) ; <br/> <br/> public function __construct ( array $content = null ) <br/> { <br/> if ( isset ( $content ) ) { <br/> $this -> content = $content ; <br/> } <br/> } <br/> <br/> public function addContent ( $content ) <br/> { <br/> if ( ! is_array ( $content ) ) { <br/> return false ; <br/> } <br/> foreach ( $content as $name => $data ) { <br/> $this -> content [ $name ] = $data ; <br/> } <br/> } <br/> <br/> public function getData ( ) <br/> { <br/> return array ( <br/> 'error' => $this -> error , <br/> 'response' => $this -> content , <br/> ) ; <br/> } <br/> } <br/> <br/> class ErrorResponse extends Response<br/> { <br/> public function __construct ( array $content = null ) <br/> { <br/> parent :: __construct ( $content ) ; <br/> $this -> error = 1 ; <br/> } <br/> } <br/> <br/> class SuccessResponse extends Response<br/> { <br/> public function __construct ( array $content = null ) <br/> { <br/> parent :: __construct ( $content ) ; <br/> $this -> error = 0 ; <br/> } <br/> }
<?php <?php <br/> require_once 'model/Response.php' ; <br/> <br/> class AbstractAMFController { <br/> <br/> protected $controller ; <br/> <br/> public function __construct ( $controllerName ) <br/> { <br/> $this -> controller = new $controllerName ( ) ; <br/> } <br/> <br/> protected function methodWrapper ( $method , $data ) { <br/> try { <br/> $result = $this -> controller -> $method ( $data ) ; <br/> $response = new SuccessResponse ( ) ; <br/> $response -> addContent ( $result ) ; <br/> } catch ( Exception $e ) { <br/> $response = new ErrorResponse ( $e -> getMessage ( ) . '\n' . $e -> getTraceAsString ( ) ) ; <br/> } <br/> } <br/> return $response -> getData ( ) ; <br/> } <br/> }
<?php <?php <br/> require_once 'model/Response.php' ; <br/> <br/> class AbstractAMFController { <br/> <br/> protected $controller ; <br/> <br/> public function __construct ( $controllerName ) <br/> { <br/> $this -> controller = new $controllerName ( ) ; <br/> } <br/> <br/> protected function methodWrapper ( $method , $data ) { <br/> try { <br/> $result = $this -> controller -> $method ( $data ) ; <br/> $response = new SuccessResponse ( ) ; <br/> $response -> addContent ( $result ) ; <br/> } catch ( Exception $e ) { <br/> $response = new ErrorResponse ( $e -> getMessage ( ) . '\n' . $e -> getTraceAsString ( ) ) ; <br/> } <br/> } <br/> return $response -> getData ( ) ; <br/> } <br/> }
class Game extends AbstractAMFController { <br/> public function __construct ( ) { <br/> parent :: __construct ( 'GameController' ) ; <br/> } <br/> <br/> public function hello ( $data ) { <br/> return $this -> methodWrapper ( 'hello' , $data ) ; <br/> } <br/> }
class GameController { <br/> <br/> public function hello ( $data ) { <br/> return 'hello' ; <br/> } <br/> } <br/> include 'wrappers.php' ;
Source: https://habr.com/ru/post/113503/
All Articles