本文整理汇总了PHP中Topxia\Service\Common\ServiceKernel类的典型用法代码示例。如果您正苦于以下问题:PHP ServiceKernel类的具体用法?PHP ServiceKernel怎么用?PHP ServiceKernel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceKernel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fillUserAttr
public function fillUserAttr($userId, $userInfo)
{
$user = ServiceKernel::instance()->createService('User.UserService')->getUser($userId);
if (!empty($userInfo['avatar'])) {
$curl = curl_init($userInfo['avatar']);
$smallName = date("Ymdhis") . "_small.jpg";
$mediumName = date("Ymdhis") . "_medium.jpg";
$largeName = date("Ymdhis") . "_large.jpg";
$smallPath = ServiceKernel::instance()->getParameter('topxia.upload.public_directory') . '/tmp/' . $smallName;
$mediumPath = ServiceKernel::instance()->getParameter('topxia.upload.public_directory') . '/tmp/' . $mediumName;
$largePath = ServiceKernel::instance()->getParameter('topxia.upload.public_directory') . '/tmp/' . $largeName;
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$imageData = curl_exec($curl);
curl_close($curl);
$tp = @fopen($smallPath, 'a');
fwrite($tp, $imageData);
fclose($tp);
$tp = @fopen($mediumPath, 'a');
fwrite($tp, $imageData);
fclose($tp);
$tp = @fopen($largePath, 'a');
fwrite($tp, $imageData);
fclose($tp);
$file = ServiceKernel::instance()->createService('Content.FileService')->uploadFile('user', new File($smallPath));
$fields[] = array('type' => 'large', 'id' => $file['id']);
$file = ServiceKernel::instance()->createService('Content.FileService')->uploadFile('user', new File($mediumPath));
$fields[] = array('type' => 'medium', 'id' => $file['id']);
$file = ServiceKernel::instance()->createService('Content.FileService')->uploadFile('user', new File($largePath));
$fields[] = array('type' => 'small', 'id' => $file['id']);
$user = ServiceKernel::instance()->createService('User.UserService')->changeAvatar($userId, $fields);
}
return $user;
}
示例2: initAlipayConfig
protected static function initAlipayConfig($name)
{
$payment = ServiceKernel::instance()->createService('System.SettingService')->get('payment', array());
$alipay_config = array();
$alipay_config['seller_email'] = empty($payment['alipay_account']) ? '' : $payment['alipay_account'];
$alipay_config['partner'] = empty($payment['alipay_key']) ? '' : $payment['alipay_key'];
//安全检验码,以数字和字母组成的32位字符
//如果签名方式设置为“MD5”时,请设置该参数
$alipay_config['key'] = empty($payment['alipay_secret']) ? '' : $payment['alipay_secret'];
//商户的私钥(后缀是.pen)文件相对路径
//如果签名方式设置为“0001”时,请设置该参数
// $alipay_config['private_key_path'] = 'key/rsa_private_key.pem';
// //支付宝公钥(后缀是.pen)文件相对路径
// //如果签名方式设置为“0001”时,请设置该参数
// $alipay_config['ali_public_key_path'] = 'key/alipay_public_key.pem';
//签名方式 不需修改
$alipay_config['sign_type'] = 'MD5';
//字符编码格式 目前支持 gbk 或 utf-8
$alipay_config['input_charset'] = 'utf-8';
//ca证书路径地址,用于curl中ssl校验
//请保证cacert.pem文件在当前文件夹目录中
$alipay_config['cacert'] = getcwd() . '\\cacert.pem';
//访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http
$alipay_config['transport'] = 'http';
return $alipay_config;
}
示例3: createOrder
public function createOrder($info)
{
$connection = ServiceKernel::instance()->getConnection();
try {
$connection->beginTransaction();
$user = $this->getCurrentUser();
if (!$user->isLogin()) {
throw $this->createServiceException('用户未登录,不能创建订单');
}
if (!ArrayToolkit::requireds($info, array('targetId', 'payment'))) {
throw $this->createServiceException('订单数据缺失,创建课程订单失败。');
}
// 获得锁
$user = $this->getUserService()->getUser($user['id'], true);
if ($this->getClassroomService()->isClassroomStudent($info['targetId'], $user['id'])) {
throw $this->createServiceException('已经是班级学员,创建订单失败。');
}
$classroom = $this->getClassroomService()->getClassroom($info['targetId']);
if (empty($classroom)) {
throw $this->createServiceException('班级不存在,创建课程订单失败。');
}
if ($classroom['private'] == 1) {
throw $this->createServiceException('该班级是封闭班级,学员不能自行加入!');
}
$order = array();
$order['userId'] = $user['id'];
$order['title'] = "购买班级《{$classroom['title']}》";
$order['targetType'] = 'classroom';
$order['targetId'] = $classroom['id'];
$order['payment'] = $info['payment'];
$order['amount'] = empty($info['amount']) ? 0 : $info['amount'];
$order['priceType'] = $info['priceType'];
$order['totalPrice'] = $info["totalPrice"];
$order['coinRate'] = $info['coinRate'];
$order['coinAmount'] = $info['coinAmount'];
$order['snPrefix'] = 'CR';
if (!empty($info['note'])) {
$order['data'] = array('note' => $info['note']);
}
if (!empty($info['coupon'])) {
$order['coupon'] = $info['coupon'];
$order['couponDiscount'] = $info['couponDiscount'];
}
$order = $this->getOrderService()->createOrder($order);
if (empty($order)) {
throw $this->createServiceException('创建订单失败!');
}
// 免费班级,就直接将订单置为已购买
if (intval($order['amount'] * 100) == 0 && intval($order['coinAmount'] * 100) == 0 && empty($order['coupon'])) {
list($success, $order) = $this->getOrderService()->payOrder(array('sn' => $order['sn'], 'status' => 'success', 'amount' => $order['amount'], 'paidTime' => time()));
$info = array('orderId' => $order['id'], 'remark' => empty($order['data']['note']) ? '' : $order['data']['note']);
$this->getClassroomService()->becomeStudent($order['targetId'], $order['userId'], $info);
}
$connection->commit();
return $order;
} catch (\Exception $e) {
$connection->rollBack();
throw $e;
}
}
示例4: parseItem
public function parseItem($url)
{
$parsers = array('YoukuVideo', 'QQVideo', 'NeteaseOpenCourse', 'TudouVideo');
$kernel = ServiceKernel::instance();
$extras = array();
if ($kernel->hasParameter('media_parser')) {
$extras = $kernel->getParameter('media_parser');
}
if ($extras['item']) {
$extrasParsers = $extras['item'];
foreach ($extrasParsers as $extrasParser) {
$class = $extrasParser['class'];
$parser = new $class();
if (!$parser->detect($url)) {
continue;
}
return $parser->parse($url);
}
}
foreach ($parsers as $parserName) {
$class = __NAMESPACE__ . "\\ItemParser\\{$parserName}ItemParser";
$parser = new $class();
if (!$parser->detect($url)) {
continue;
}
return $parser->parse($url);
}
throw $this->createParserNotFoundException();
}
示例5: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST && $request->getMethod() == 'POST') {
if (stripos($request->getPathInfo(), '/mapi') === 0) {
return;
}
if (stripos($request->getPathInfo(), '/hls') === 0) {
return;
}
$whiteList = array('/coin/pay/return/alipay', '/coin/pay/notify/alipay', '/coin/pay/notify/wxpay', '/pay/center/pay/alipay/return', '/pay/center/pay/wxpay/notify', '/pay/center/pay/alipay/notify', '/live/verify', '/course/order/pay/alipay/notify', '/vip/pay_notify/alipay', '/uploadfile/upload', '/uploadfile/cloud_convertcallback', '/uploadfile/cloud_convertcallback2', '/uploadfile/cloud_convertcallback3', '/uploadfile/cloud_convertheadleadercallback', '/disk/upload', '/file/upload', '/editor/upload', '/disk/convert/callback', '/partner/phpwind/api/notify', '/partner/discuz/api/notify', '/live/auth', '/edu_cloud/sms_callback');
if (in_array($request->getPathInfo(), $whiteList)) {
return;
}
if ($request->isXmlHttpRequest()) {
$token = $request->headers->get('X-CSRF-Token');
} else {
$token = $request->request->get('_csrf_token', '');
}
$request->request->remove('_csrf_token');
$expectedToken = $this->container->get('form.csrf_provider')->generateCsrfToken('site');
if ($token != $expectedToken) {
// @todo 需要区分ajax的response
if ($request->getPathInfo() == '/admin') {
$token = $request->request->get('token');
$result = ServiceKernel::instance()->createService('CloudPlatform.AppService')->repairProblem($token);
$this->container->set('Topxia.RepairProblem', $result);
} else {
$response = $this->container->get('templating')->renderResponse('TopxiaWebBundle:Default:message.html.twig', array('type' => 'error', 'message' => '页面已过期,请重新提交数据!', 'goto' => '', 'duration' => 0));
$event->setResponse($response);
}
}
}
}
示例6: lessonHomeworkListAction
public function lessonHomeworkListAction(Request $request, $courseId, $lessonId)
{
$course = ServiceKernel::instance()->createService('Course.CourseService')->getCourse($courseId);
$lesson = ServiceKernel::instance()->createService('Course.CourseService')->getCourseLesson($courseId, $lessonId);
$homeworkService = $this->getHomeworkService();
$homework = $homeworkService->findHomeworkByLessonId($lessonId);
$homeworkMemberService = $this->getHomeworkMemberService();
$homework_members = $homeworkMemberService->findHomeworkMembersByLessonId($lessonId);
$conditions = array();
$conditions['lesson_id'] = $lesson['id'];
$orderBy = array();
$orderBy[] = 'create_at';
$orderBy[] = 'DESC';
$count = $homeworkMemberService->searchHomeworkMembersCount($conditions);
$page_size = 20;
$paginator = new Paginator($request, $count, $page_size);
$start = $paginator->getOffsetCount();
$limit = $paginator->getPerPageCount();
$homework_members = $homeworkMemberService->searchHomeworkMembers($conditions, $orderBy, $start, $limit);
$homework_members = $this->addUser($homework_members);
$tpl = 'HomeworkBundle:Homework:lesson-homework-list.html.twig';
$assignBox = array();
$assignBox['course'] = $course;
$assignBox['lesson'] = $lesson;
$assignBox['homework'] = $homework;
$assignBox['homework_members'] = $homework_members;
$assignBox['paginator'] = $paginator;
return $this->render($tpl, $assignBox);
}
示例7: processOrder
public function processOrder($payData, $lock = true)
{
$connection = ServiceKernel::instance()->getConnection();
try {
if ($lock) {
$connection->beginTransaction();
}
list($success, $order) = $this->getOrderService()->payOrder($payData);
if ($order["coupon"]) {
$this->useCoupon($order);
}
$processor = OrderProcessorFactory::create($order["targetType"]);
if ($order['status'] == 'paid' && $processor) {
$processor->doPaySuccess($success, $order);
}
if ($lock) {
$connection->commit();
}
return array($success, $order);
} catch (\Exception $e) {
if ($lock) {
$connection->rollback();
}
throw $e;
}
return array(false, array());
}
示例8: convert
public function convert($id)
{
$thread = ServiceKernel::instance()->createService('Course.ThreadService')->getThread(1, $id);
if (empty($thread)) {
throw new \Exception('course-thread not found');
}
return $thread;
}
示例9: initServiceKernel
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);
}
示例10: convert
public function convert($id)
{
$homework = ServiceKernel::instance()->createService('Homework:Homework.HomeworkService')->gethomework($id);
if (empty($homework)) {
throw new \Exception('user not found');
}
return $homework;
}
示例11: backupdb
public static function backupdb()
{
$backUpdir = SystemUtil::getUploadTmpPath();
$backUpdir .= DIRECTORY_SEPARATOR . uniqid(mt_rand()) . '.txt';
$dbSetting = array('exclude' => array('session', 'cache'));
$dump = new MySQLDumper(ServiceKernel::instance()->getConnection(), $dbSetting);
return $dump->export($backUpdir);
}
示例12: getSchoolApps
private function getSchoolApps()
{
$mobile = ServiceKernel::instance()->createService('System.SettingService')->get('mobile');
$site = ServiceKernel::instance()->createService('System.SettingService')->get('site');
$apps[1] = array('id' => "1", 'code' => 'announcement', 'name' => $site['name'], 'title' => $site['slogan'], 'about' => $mobile['about'], 'avatar' => $mobile['logo'], 'callback' => '/mobileschools/announcements');
$apps[2] = array('id' => "2", 'code' => 'news', 'name' => '资讯', 'title' => '网校资讯服务', 'about' => '', 'avatar' => 'img/mobile/article_app_icon.jpg', 'callback' => '');
return $apps;
}
示例13: convert
public function convert($id)
{
$post = ServiceKernel::instance()->createService('Course.ThreadService')->getPost(1, $id);
if (empty($post)) {
throw new \Exception('course-thread-post not found');
}
return $post;
}
示例14: initServiceKernel
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);
}
示例15: convert
public function convert($id)
{
$announcement = ServiceKernel::instance()->createService('Announcement.AnnouncementService')->getAnnouncement($id);
if (empty($announcement)) {
throw new \Exception('announcement not found');
}
return $announcement;
}