コード例 #1
0
ファイル: Executable.php プロジェクト: nurcahyo/juriya
 /**
  * Handle observer removal
  *
  * @param  object Juriya\Pattern\Observer
  * @return void
  */
 public function detach($observer)
 {
     if (!$observer instanceof Observer) {
         throw new \InvalidArgumentException(I18n::translate('observer_invalid_detach', __CLASS__));
     }
     $existObserver = array_search($observer, $this->observers);
     if ($existObserver !== FALSE) {
         unset($this->observers[$existObserver]);
     }
 }
コード例 #2
0
ファイル: Exception.php プロジェクト: nurcahyo/juriya
 /**
  * Exception instantiation process
  *
  * @param  mixed    PHP Exception/Error
  * @throws object   RuntimeException
  * @return void
  */
 function __construct($e)
 {
     // Set appropriate properties
     if (is_array($e)) {
         $this->error = $e;
     } elseif (is_object($e)) {
         $this->exception = $e;
     } else {
         throw new \RuntimeException(I18n::translate('cannot_handle_exception'));
     }
 }
コード例 #3
0
ファイル: Console.php プロジェクト: nurcahyo/juriya
 /**
  * Main console runner
  *
  * @return stream
  */
 public static function execute()
 {
     self::out(I18n::translate('command_hello', Juriya::version()) . "\n");
     self::processArguments($_SERVER['argv']);
     self::out();
 }
コード例 #4
0
ファイル: File.php プロジェクト: nurcahyo/juriya
 /**
  * Append to a file.
  *
  * @param  string    File path
  * @param  string    content
  * @throws object    UnexpectedValueException
  * @return int
  */
 public static function append($path, $data)
 {
     // @codeCoverageIgnoreStart
     if (!($handle = fopen($path, 'a+'))) {
         throw new \UnexpectedValueException(I18n::translate('file_not_writable', $path));
     }
     // @codeCoverageIgnoreEnd
     fwrite($handle, $data);
     fclose($handle);
     substr(sprintf('%o', fileperms($path)), -4) == '0777' or chmod($path, 0777);
     return;
 }
コード例 #5
0
ファイル: Request.php プロジェクト: nurcahyo/juriya
 /**
  * Manufacturing Juriya Request
  *
  * Prototype :
  * 	Request::factory('foo');
  *	Request::factory('foo.bar', array('foo', 'bar'), 'cli');
  *
  * @param   string  controller name or module path
  * @param   string  input arguments
  * @param   string  input tunnel
  * @throws  object  RangeException
  * @throws  object  LogicException
  * @return  object  Juriya\Input
  */
 public static function factory($controller = '', $arguments = array(), $tunnel = 'hmvc')
 {
     // Validate tunnel
     if (!in_array(strtolower($tunnel), array('hmvc', 'http', 'cli'))) {
         throw new \RangeException(I18n::translate('invalid', 'Tunnel'));
     }
     // Set the input tunnel and path
     $tunnel = strtoupper($tunnel);
     $path = explode('.', $controller);
     // Initial empty name
     $controllerName = '';
     // Guess whether to use Module or App controller
     if (count($path) == 2) {
         $ns = '\\' . ucfirst($path[0]) . '\\Controller\\';
         $controllerName = ucfirst($path[1]);
     } elseif (count($path) == 1) {
         $ns = '\\App\\Controller\\';
         $controllerName = ucfirst($controller);
     } else {
         throw new \LogicException(I18n::translate('cannot_handle_subdirectory'));
     }
     // Set the socket and build the collection config
     $socket = $ns . $controllerName . 'Controller';
     $config = new Collection(compact('path', 'tunnel', 'arguments', 'socket'));
     return new static($config);
 }
コード例 #6
0
ファイル: I18nTest.php プロジェクト: nurcahyo/juriya
 public function testOnlyInstatiatedOnce()
 {
     I18n::setLocale('en');
     $this->setExpectedException('RuntimeException', 'Class ' . get_class(I18n::getInstance()) . ' already initialized');
     $newI18n = new I18n();
 }
コード例 #7
0
ファイル: Juriya.php プロジェクト: nurcahyo/juriya
 /**
  * Framework runner
  *
  * @return object Juriya\Output
  * @throws object InvalidArgumentException
  */
 public function execute()
 {
     // Get the input, and doing initial validation
     $inputs = func_get_args();
     if (empty($inputs)) {
         throw new \InvalidArgumentException(I18n::translate('input_empty'));
     }
     // Validate the input request
     $request = current($inputs);
     if (!$request instanceof Input) {
         throw new \InvalidArgumentException(I18n::translate('input_invalid'));
     }
     // Fetch the response from current request
     $response = $this->handleRequest($request);
     // Run the observer hooks
     $this->notify($this, $response);
     // Send the response output
     return $response->render();
 }