コード例 #1
0
 public function callback($data)
 {
     try {
         $this->verifyCallbackParameters($data);
         $order = $this->getCallbackOrder(fnGet($data, 'order_id'));
         $this->verifyCallbackSign($order, $data, fnGet($data, 'sign'));
         $status = fnGet($data, 'status');
         if ($status == 'complete') {
             if ($order->canComplete()) {
                 $this->verifyCallbackAmount($order, fnGet($data, 'amount'));
                 $order->complete('Test Callback');
                 $order->save();
             }
             return Result::create(['order' => $order, 'response' => 'OK']);
         }
         $failureMessage = fnGet($data, 'failure_message');
         if ($order->canFail()) {
             $order->fail($failureMessage);
             $order->save();
         }
         return Result::create(['error' => $failureMessage, 'response' => 'OK']);
     } catch (CallbackException $e) {
         return Result::create(['error' => $e, 'response' => 'FAILED']);
     } catch (Exception $e) {
         Log::exception($e);
         return Result::create(['error' => $e, 'response' => 'FAILED']);
     }
 }
コード例 #2
0
ファイル: TestCase.php プロジェクト: phwoolcon/bootstrap
 public function setUp()
 {
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     $this->di = Di::getDefault();
     Cache::flush();
     Config::clearCache();
     PHPUnit_Framework_TestCase::setUp();
     $class = get_class($this);
     Log::debug("Running {$class}::{$this->getName()}() ...");
 }
コード例 #3
0
ファイル: functions.php プロジェクト: phwoolcon/bootstrap
function exceptionHandler(Exception $exception)
{
    profilerStop();
    Log::exception($exception);
    if ($exception instanceof HttpException) {
        $response = $exception->toResponse();
        $response->send();
        return;
    }
    sendHttpStatus(500);
    header('content-type: application/json');
    echo json_encode(['error_code' => 500, 'error_msg' => 'Server down, please check log!']);
}
コード例 #4
0
ファイル: RouterTest.php プロジェクト: phwoolcon/phwoolcon
 /**
  * @param string $uri
  * @param string $method
  * @return CsrfException|NotFoundException|Response
  */
 protected function dispatch($uri, $method = 'GET')
 {
     $_SERVER['REQUEST_METHOD'] = $method;
     $router = $this->getRouter();
     $router::staticReset();
     Cookies::reset();
     $this->getView()->reset();
     try {
         return $router->dispatch($uri);
     } catch (Exception $e) {
         Log::exception($e);
         return $e;
     }
 }
コード例 #5
0
ファイル: Db.php プロジェクト: phwoolcon/phwoolcon
 public function __construct($config)
 {
     $this->config = $config;
     $ormOptions = $config['orm_options'];
     $ormOptions['distributed'] = $config['distributed'];
     Model::setup($ormOptions);
     if (fnGet($this->config, 'query_log')) {
         Events::attach('db:beforeQuery', function (Event $event) {
             /* @var Adapter $adapter */
             $adapter = $event->getSource();
             $binds = $adapter->getSqlVariables();
             Log::debug($adapter->getSQLStatement() . '; binds = ' . var_export($binds, 1));
         });
     }
 }
コード例 #6
0
ファイル: AdapterTrait.php プロジェクト: phwoolcon/auth
 public function activatePendingConfirmationUser($confirmationCode)
 {
     /* @var User $userModel */
     $userModel = $this->userModel;
     if (!($userData = $this->getPendingConfirmationData()) || !($uid = fnGet($userData, $this->uidKey)) || $confirmationCode != fnGet($userData, 'confirmation_code') || $userModel::findFirstSimple([$this->uidKey => $uid])) {
         return false;
     }
     /* @var User $user */
     $user = new $this->userModel();
     $user->setData($userData)->setData('confirmed', true);
     if (!$user->save()) {
         Log::error('User activation failed on save: ' . var_export($user->getStringMessages(), true));
         return false;
     }
     $this->removePendingConfirmationData();
     $this->setUserAsLoggedIn($user);
     return $user;
 }
コード例 #7
0
ファイル: SsoTrait.php プロジェクト: phwoolcon/auth
 protected function getSsoUserData($input)
 {
     try {
         $site = SsoSite::getSiteDataByReturnUrl(fnGet($input, 'notifyUrl'));
         $initToken = fnGet($input, 'initToken');
         $initTime = fnGet($input, 'initTime');
         if (!$this->checkInitToken($initTime, $initToken, $site)) {
             return ['error' => __('Invalid SSO init token')];
         }
         if (!($user = Auth::getUser())) {
             return ['error' => false, 'user_data' => ['uid' => null]];
         }
         $ssoData = ['error' => false, 'user_data' => ['uid' => $user->getId(), 'username' => $user->getUsername(), 'email' => $user->getEmail(), 'avatar' => $user->getAvatar()], 'user' => $user, 'site' => $site];
         return $ssoData;
     } catch (Exception $e) {
         Log::exception($e);
         return ['error' => __('Other error %code% - %time%', ['code' => $e->getCode(), 'time' => date(DateTime::MYSQL_DATETIME)])];
     }
 }
コード例 #8
0
ファイル: ResourceTrait.php プロジェクト: phwoolcon/phwoolcon
 public function getContent($basePath = null)
 {
     if ($this->content === null) {
         if (ResourceTrait::$runningUnitTest) {
             Log::debug(sprintf('Asset path: [%s]', $this->_path));
         }
         try {
             if ($this->_local) {
                 $this->content = parent::getContent($basePath);
             } else {
                 $path = $this->_path;
                 substr($this->_path, 0, 2) == '//' and $path = 'http:' . $path;
                 $this->content = file_get_contents($path, false, stream_context_create(['http' => ['method' => 'GET', 'timeout' => 1]]));
             }
         } catch (Exception $e) {
             Log::exception($e);
             $this->content = '';
         }
     }
     return $this->content;
 }
コード例 #9
0
ファイル: AbstractTrait.php プロジェクト: phwoolcon/payment
 public function callback($data)
 {
     try {
         $this->verifyCallbackParameters($data);
         $this->verifyCallbackSign(null, $data, fnGet($data, 'sign'));
         $order = $this->getCallbackOrder(fnGet($data, 'out_trade_no'));
         $status = fnGet($data, 'trade_status');
         // Processing
         if ($status == 'WAIT_BUYER_PAY') {
             if ($order->canConfirm()) {
                 $order->confirm(__('Alipay callback status %status%', ['status' => $status]));
                 $order->save();
             }
             return Result::create(['order' => $order, 'response' => 'success']);
         }
         // Success
         if ($status == 'TRADE_FINISHED' || $status == 'TRADE_SUCCESS') {
             if ($order->canComplete()) {
                 $this->verifyCallbackAmount($order, fnGet($data, 'total_fee'));
                 $order->complete('Test Callback');
                 $order->save();
             }
             return Result::create(['order' => $order, 'response' => 'success']);
         }
         // Failure
         if ($order->canFail()) {
             $order->fail(__('Alipay callback status %status%', ['status' => $status]));
             $order->save();
         }
         return Result::create(['order' => $order, 'response' => 'success']);
     } catch (CallbackException $e) {
         return Result::create(['error' => $e, 'response' => 'FAILED']);
     } catch (Exception $e) {
         Log::exception($e);
         return Result::create(['error' => $e, 'response' => 'FAILED']);
     }
     // @codeCoverageIgnoreEnd
 }
コード例 #10
0
ファイル: MigrateRevert.php プロジェクト: phwoolcon/phwoolcon
 protected function revertMigration($filename)
 {
     $db = $this->db;
     $db->begin();
     $file = migrationPath($filename);
     try {
         $this->logAndShowInfo(sprintf('Start reverting migration "%s"', $filename));
         $migration = (include $file);
         if (isset($migration['down']) && is_callable($migration['down'])) {
             call_user_func($migration['down'], $db, $this);
         }
         $this->migrationExecuted($filename, false);
         $db->commit();
         Db::clearMetadata();
         $this->logAndShowInfo(sprintf('Finish reverting migration "%s"', $filename));
     } catch (Exception $e) {
         $db->rollback();
         Log::exception($e);
         $this->error(sprintf('Error when reverting migration "%s"', $filename));
         $this->error($e->getMessage());
     }
     // @codeCoverageIgnoreEnd
 }
コード例 #11
0
ファイル: Router.php プロジェクト: phwoolcon/phwoolcon
 public static function dispatch($uri = null)
 {
     try {
         static::$router === null and static::$router = static::$di->getShared('router');
         $router = static::$router;
         // @codeCoverageIgnoreStart
         if (!$uri && $router->_sitePathLength && $router->_uriSource == self::URI_SOURCE_GET_URL) {
             list($uri) = explode('?', $_SERVER['REQUEST_URI']);
             $uri = str_replace(basename($_SERVER['SCRIPT_FILENAME']), '', $uri);
             if (substr($uri, 0, $router->_sitePathLength) == $router->_sitePathPrefix) {
                 $uri = substr($uri, $router->_sitePathLength);
             }
         }
         // @codeCoverageIgnoreEnd
         Events::fire('router:before_dispatch', $router, ['uri' => $uri]);
         $router->handle($uri);
         $route = $router->getMatchedRoute() or static::throw404Exception();
         static::$disableSession or Session::start();
         static::$disableCsrfCheck or static::checkCsrfToken();
         if (($controllerClass = $router->getControllerName()) instanceof Closure) {
             $response = $controllerClass();
             if (!$response instanceof Response) {
                 /* @var Response $realResponse */
                 $realResponse = static::$di->getShared('response');
                 $realResponse->setContent($response);
                 $response = $realResponse;
             }
         } else {
             /* @var Controller $controller */
             $controller = new $controllerClass();
             method_exists($controller, 'initialize') and $controller->initialize();
             method_exists($controller, $method = $router->getActionName()) or static::throw404Exception();
             $controller->{$method}();
             $response = $controller->response;
         }
         Events::fire('router:after_dispatch', $router, ['response' => $response]);
         Session::end();
         return $response;
     } catch (HttpException $e) {
         Log::exception($e);
         return static::$runningUnitTest ? $e : $e->toResponse();
     }
 }
コード例 #12
0
ファイル: View.php プロジェクト: phwoolcon/phwoolcon
 public function render($controllerName, $actionName, $params = null)
 {
     try {
         $this->start();
         $result = parent::render($controllerName, $actionName, $params);
         $this->finish();
         $this->response->setContent($this->getContent());
         return $result;
     } catch (ViewException $e) {
         Log::exception($e);
         return false;
     } catch (Exception $e) {
         throw $e;
     }
     // @codeCoverageIgnoreEnd
 }
コード例 #13
0
ファイル: MethodTrait.php プロジェクト: phwoolcon/payment
 protected function throwCallbackException($message, $code)
 {
     $e = new CallbackException($message, $code);
     Log::exception($e);
     throw $e;
 }
コード例 #14
0
ファイル: TestService.php プロジェクト: phwoolcon/phwoolcon
 public function stop($instance = 'current')
 {
     parent::stop($instance);
     if ($serviceInfo = $this->getServiceInfo($instance)) {
         list(, , $port) = array_values($serviceInfo);
         $this->showStatus($port, false, $error);
         $retry = 10;
         while (!$error) {
             usleep(100000.0);
             $this->showStatus($port, false, $error);
             --$retry;
         }
         $error or Log::error('Unable to stop instance: ' . $instance);
     }
 }
コード例 #15
0
ファイル: Migrate.php プロジェクト: phwoolcon/phwoolcon
 protected function runMigration()
 {
     $db = $this->db;
     $migrated = false;
     foreach (glob(migrationPath('*.php')) as $file) {
         $filename = basename($file);
         if ($this->migrationExecuted($filename)) {
             continue;
         }
         $migrated = true;
         $this->logAndShowInfo(sprintf('Start migration "%s"', $filename));
         $db->begin();
         try {
             $migration = (include $file);
             if (isset($migration['up']) && is_callable($migration['up'])) {
                 call_user_func($migration['up'], $db, $this);
             }
             $this->migrationExecuted($filename, true);
             $db->commit();
         } catch (Exception $e) {
             $db->rollback();
             Log::exception($e);
             $this->error(sprintf('Error in migration "%s"', $filename));
             $this->error($e->getMessage());
             return;
         }
         // @codeCoverageIgnoreEnd
         $this->logAndShowInfo(sprintf('Finish migration "%s"', $filename));
     }
     if ($migrated) {
         Db::clearMetadata();
     } else {
         $this->info('Nothing to be migrated.');
     }
     // @codeCoverageIgnoreEnd
 }
コード例 #16
0
ファイル: TestCase.php プロジェクト: phwoolcon/phwoolcon
 public function tearDown()
 {
     $elapsed = Timer::stop();
     parent::tearDown();
     Log::debug("================== Finished, time elapsed: {$elapsed}. ==================");
 }
コード例 #17
0
ファイル: di.php プロジェクト: phwoolcon/phwoolcon
use Phalcon\Version;
use Phwoolcon\Aliases;
use Phwoolcon\Cache;
use Phwoolcon\Config;
use Phwoolcon\Cookies;
use Phwoolcon\Db;
use Phwoolcon\DiFix;
use Phwoolcon\Events;
use Phwoolcon\I18n;
use Phwoolcon\Log;
use Phwoolcon\Queue;
use Phwoolcon\Router;
use Phwoolcon\Session;
use Phwoolcon\Util\Counter;
use Phwoolcon\View;
$_SERVER['PHWOOLCON_PHALCON_VERSION'] = Version::getId();
Events::register($di);
DiFix::register($di);
Db::register($di);
Cache::register($di);
Log::register($di);
Config::register($di);
Counter::register($di);
Aliases::register($di);
Router::register($di);
I18n::register($di);
Cookies::register($di);
Session::register($di);
View::register($di);
Queue::register($di);
$loader->registerNamespaces(Config::get('app.autoload.namespaces', []), true);
コード例 #18
0
ファイル: I18n.php プロジェクト: phwoolcon/phwoolcon
 protected function logUndefinedLocaleString($string, $package)
 {
     $package = (string) $package;
     if (isset($this->undefinedStrings[$this->currentLocale][$package][$string])) {
         return;
     }
     Log::warning("I18n: locale string not found: '{$string}'");
     is_file($this->undefinedStringsLogFile) and $this->undefinedStrings = (include $this->undefinedStringsLogFile);
     $this->undefinedStrings[$this->currentLocale][$package][$string] = true;
     fileSaveArray($this->undefinedStringsLogFile, $this->undefinedStrings);
 }