private function initServiceKernel() { $serviceKernel = ServiceKernel::create('dev', false); $serviceKernel->setConnection($this->getContainer()->get('database_connection')); $currentUser = new CurrentUser(); $currentUser->fromArray(array('id' => 1, 'nickname' => '测试管理员', 'currentIp' => '127.0.0.1', 'roles' => array("ROLE_SUPER_ADMIN"))); $serviceKernel->setCurrentUser($currentUser); }
private function initServiceKernel() { global $kernel; $serviceKernel = ServiceKernel::create('dev', false); $serviceKernel->setParameterBag($kernel->getContainer()->getParameterBag()); $serviceKernel->setConnection($kernel->getContainer()->get('database_connection')); return $serviceKernel; }
private function initServiceKernel() { $serviceKernel = ServiceKernel::create('dev', false); $serviceKernel->setParameterBag($this->getContainer()->getParameterBag()); $serviceKernel->setConnection($this->getContainer()->get('database_connection')); $user = $this->getUserService()->getUser(1); $serviceKernel->setCurrentUser($user); }
private function initServiceKernel() { $serviceKernel = ServiceKernel::create('dev', false); $serviceKernel->setParameterBag($this->getContainer()->getParameterBag()); $serviceKernel->setConnection($this->getContainer()->get('database_connection')); $currentUser = new CurrentUser(); $currentUser->fromArray(array('id' => 0, 'nickname' => '游客', 'currentIp' => '127.0.0.1', 'roles' => array())); $serviceKernel->setCurrentUser($currentUser); }
protected function initServiceKernel() { $serviceKernel = ServiceKernel::create('dev', true); $serviceKernel->setParameterBag($this->getContainer()->getParameterBag()); $serviceKernel->registerModuleDirectory(dirname(__DIR__) . '/plugins'); $serviceKernel->setConnection($this->getContainer()->get('database_connection')); $currentUser = new CurrentUser(); $currentUser->fromArray(array('id' => 0, 'nickname' => '游客', 'currentIp' => '127.0.0.1', 'roles' => array())); $serviceKernel->setCurrentUser($currentUser); }
/** * 每个testXXX执行之前,都会执行此函数,净化数据库。 * * NOTE: 如果数据库已创建,那么执行清表操作,不重建。 */ private function setServiceKernel() { $kernel = new \AppKernel('test', false); $kernel->loadClassCache(); $kernel->boot(); Request::enableHttpMethodParameterOverride(); $request = Request::createFromGlobals(); $serviceKernel = ServiceKernel::create($kernel->getEnvironment(), $kernel->isDebug()); $serviceKernel->setParameterBag($kernel->getContainer()->getParameterBag()); $serviceKernel->setConnection($kernel->getContainer()->get('database_connection')); $currentUser = new CurrentUser(); $currentUser->fromArray(array('id' => 1, 'nickname' => 'admin', 'email' => '*****@*****.**', 'password' => 'admin', 'currentIp' => '127.0.0.1', 'roles' => array('ROLE_USER', 'ROLE_ADMIN', 'ROLE_SUPER_ADMIN', 'ROLE_TEACHER'))); $serviceKernel->setCurrentUser($currentUser); $this->serviceKernel = $serviceKernel; }
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\JsonResponse; use Topxia\Service\Common\ServiceKernel; use Topxia\Service\User\CurrentUser; use Doctrine\DBAL\DriverManager; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\Debug\ErrorHandler; use Symfony\Component\Debug\ExceptionHandler; // use Symfony\Component\Debug\Debug; // Debug::enable(); ErrorHandler::register(); ExceptionHandler::register(); $config = (include __DIR__ . '/config.php'); $config['host'] = 'http://' . $_SERVER['HTTP_HOST']; $connection = DriverManager::getConnection(array('dbname' => $config['database_name'], 'user' => $config['database_user'], 'password' => $config['database_password'], 'host' => $config['database_host'], 'driver' => $config['database_driver'], 'charset' => 'utf8')); $serviceKernel = ServiceKernel::create($config['environment'], true); $serviceKernel->setParameterBag(new ParameterBag($config)); $serviceKernel->setConnection($connection); // $serviceKernel->getConnection()->exec('SET NAMES UTF8'); include __DIR__ . '/src/functions.php'; $app = new Silex\Application(); $app->register(new Silex\Provider\ServiceControllerServiceProvider()); $app['debug'] = true; $app->view(function (array $result, Request $request) use($app) { return new JsonResponse($result); }); include __DIR__ . '/config/container.php'; $app->before(function (Request $request) use($app) { $whiteLists = (include __DIR__ . '/whiteList.php'); $whiteLists = $request->getMethod() == 'GET' ? $whiteLists['get'] : $whiteLists['post']; $inWhiteList = 0;
/** * 生产Key */ function install_step999() { if (empty($_COOKIE['nokey'])) { if (empty($_SESSION)) { session_start(); } $connection = _create_connection(); $serviceKernel = ServiceKernel::create('prod', true); $serviceKernel->setParameterBag(new ParameterBag(array('kernel' => array('root_dir' => realpath(__DIR__ . '/../../app'))))); $serviceKernel->setConnection($connection); $init = new SystemInit(); $key = $init->initKey(); echo json_encode($key); } else { echo json_encode(array('accessKey' => '__NOKEY__', 'secretKey' => '__NOKEY__')); } }
} use Symfony\Component\Debug\Debug; use Topxia\Service\User\CurrentUser; use Topxia\Service\Common\ServiceKernel; use Symfony\Component\HttpFoundation\Request; fix_gpc_magic(); $loader = (require_once __DIR__ . '/../app/bootstrap.php.cache'); Debug::enable(); require_once __DIR__ . '/../app/AppKernel.php'; $kernel = new AppKernel('dev', true); $kernel->loadClassCache(); Request::enableHttpMethodParameterOverride(); $request = Request::createFromGlobals(); $kernel->boot(); // START: init service kernel $serviceKernel = ServiceKernel::create($kernel->getEnvironment(), $kernel->isDebug()); $serviceKernel->setEnvVariable(array('host' => $request->getHttpHost(), 'schemeAndHost' => $request->getSchemeAndHttpHost(), 'basePath' => $request->getBasePath(), 'baseUrl' => $request->getSchemeAndHttpHost() . $request->getBasePath())); $serviceKernel->setParameterBag($kernel->getContainer()->getParameterBag()); $serviceKernel->registerModuleDirectory(dirname(__DIR__) . '/plugins'); $serviceKernel->setConnection($kernel->getContainer()->get('database_connection')); $serviceKernel->getConnection()->exec('SET NAMES UTF8'); $currentUser = new CurrentUser(); $currentUser->fromArray(array('id' => 0, 'nickname' => '游客', 'currentIp' => $request->getClientIp(), 'roles' => array())); $serviceKernel->setCurrentUser($currentUser); // END: init service kernel // NOTICE: 防止请求捕捉失败而做异常处理 // 包括:数据库连接失败等 try { $response = $kernel->handle($request); } catch (\RuntimeException $e) { echo "Error! " . $e->getMessage();
use Topxia\Api\ApiAuth; use Symfony\Component\Debug\Exception\FlattenException; use Symfony\Component\Debug\ErrorHandler; use Symfony\Component\Debug\ExceptionHandler; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\Debug\Debug; if (API_ENV == 'prod') { ErrorHandler::register(0); ExceptionHandler::register(false); } $paramaters = (include __DIR__ . '/config/paramaters.php'); $paramaters['host'] = 'http://' . $_SERVER['HTTP_HOST']; $connection = DriverManager::getConnection(array('wrapperClass' => 'Topxia\\Service\\Common\\Connection', 'dbname' => $paramaters['database_name'], 'user' => $paramaters['database_user'], 'password' => $paramaters['database_password'], 'host' => $paramaters['database_host'], 'driver' => $paramaters['database_driver'], 'charset' => 'utf8')); $serviceKernel = ServiceKernel::create($paramaters['environment'], true); $serviceKernel->setParameterBag(new ParameterBag($paramaters)); $serviceKernel->setConnection($connection); include __DIR__ . '/src/functions.php'; $app = new Silex\Application(); include __DIR__ . '/config/' . API_ENV . '.php'; $app->register(new Silex\Provider\ServiceControllerServiceProvider()); $app->view(function (array $result, Request $request) use($app) { // 兼容气球云搜索的接口 $documentType = $request->headers->get('X-Search-Document'); if ($documentType) { $class = "Topxia\\Api\\SpecialResponse\\{$documentType}Response"; if (!class_exists($class)) { throw new \RuntimeException("{$documentType}Response不存在!"); } $obj = new $class();
function install_step3() { check_installed(); global $twig; $connection = _create_connection(); $serviceKernel = ServiceKernel::create('prod', true); $serviceKernel->setConnection($connection); // $serviceKernel->setParameterBag($kernel->getContainer()->getParameterBag()); $error = null; if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { $init = new SystemInit(); $admin = $init->initAdmin($_POST['admin']); $init->initSiteSettings($_POST); $init->initRegisterSetting($admin); $init->initMailerSetting($_POST['sitename']); $init->initPaymentSetting(); $init->initStorageSetting(); $init->initTag(); $init->initCategory(); $init->initFile(); $init->initPages(); $init->initNavigations(); $init->initBlocks(); $init->initThemes(); $init->initLockFile(); $init->initRefundSetting(); $init->initArticleSetting(); $web = $_POST['web']; $userData = array(); $userData['server_addr'] = $_SERVER['SERVER_ADDR']; $userData['server_name'] = $_SERVER['SERVER_NAME']; $userData['mobile'] = $web['mobile']; $userData['qq'] = $web['qq']; $userData['name'] = $web['name']; _postRequest("http://open.edusoho.com/track/install", $userData); header("Location: start-install.php?step=4"); exit; } echo $twig->render('step-3.html.twig', array('step' => 3, 'error' => $error, 'request' => $_POST)); }