コード例 #1
0
 /**
  * New page (post).
  *
  * @Post("new", as="pastebin.new")
  *
  * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function postNew()
 {
     $data = [];
     $data['code'] = $this->request('code');
     $data['description'] = $this->request('description');
     $data['hash'] = str_random(5);
     $data['protect'] = $this->request('protect') === '1';
     if ($this->session('twitter.login', false)) {
         $data['user_id'] = $this->session('twitter.me.id');
         $data['user_sn'] = $this->session('twitter.me.sn');
     }
     $validate = $this->pasteBin->insert($data, ['save' => true]);
     if ($validate === true) {
         return redirect("/pastebin/show/{$data['hash']}")->with('message', '作成が完了しました。');
     }
     return redirect()->back()->withErrors($validate->errors());
 }
コード例 #2
0
 /**
  * pastebin/create API.
  *
  * @Any("create", as="api.pastebin.create")
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function anyCreate()
 {
     try {
         $hash = str_random(5);
         $insert = [];
         foreach (['description', 'code', 'protect'] as $v) {
             $insert[$v] = $this->request($v);
         }
         $insert['hash'] = $hash;
         $validate = $this->pasteBin->insert($insert, ['save' => true]);
         if ($validate === true) {
             $data = $this->pasteBin->where('hash', $hash)->get()->first();
             return $this->onSuccess($data);
         }
         throw new RuntimeException($validate->errors()->first(), 400);
     } catch (Exception $e) {
         return $this->onError($e);
     }
 }
コード例 #3
0
ファイル: PasteBinTest.php プロジェクト: Hiroto-K/HkApps
 /**
  * Test insert method.
  *
  * @dataProvider insertDataProvider
  *
  * @param mixed $hash
  * @param mixed $description
  * @param mixed $code
  * @param mixed $protect
  * @param mixed $user_id
  * @param mixed $user_sn
  * @param bool  $hasError
  */
 public function testInsert($hash, $description, $code, $protect, $user_id, $user_sn, $hasError)
 {
     $data = compact('hash', 'description', 'code', 'protect', 'user_id', 'user_sn');
     $response = $this->pasteBin->insert($data);
     $this->checkError($response, $hasError);
 }