當前位置: 首頁>>代碼示例>>PHP>>正文


PHP R::dispense方法代碼示例

本文整理匯總了PHP中RedBeanPHP\R::dispense方法的典型用法代碼示例。如果您正苦於以下問題:PHP R::dispense方法的具體用法?PHP R::dispense怎麽用?PHP R::dispense使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在RedBeanPHP\R的用法示例。


在下文中一共展示了R::dispense方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __invoke

 public function __invoke(Request $req, Response $res, callable $next)
 {
     $res = $next($req, $res);
     $identity = $this->authService->getIdentity();
     if (!$identity) {
         return $res;
     }
     try {
         $user = R::findOne('user', 'mail = ?', [$identity->mail]);
         if (!$user) {
             $user = R::dispense('user');
             $user->uid = $identity->uid;
             $user->mail = $identity->mail;
             $user->display_name = $identity->displayName;
             $user->office_name = $identity->officeName;
             $user->authentication_source = $identity->authenticationSource;
             $user->password = '';
             $user->created = time();
             $user->role = 'school';
             $this->logger->info(sprintf('User %s imported from sso.sch.gr to database', $identity->mail));
         }
         $user->last_login = time();
         $user_id = R::store($user);
         $identityClass = get_class($identity);
         $newIdentity = new $identityClass($user_id, $user->uid, $user->mail, $user->display_name, $user->office_name, $user->authentication_source);
         $this->authService->getStorage()->write($newIdentity);
     } catch (\Exception $e) {
         $this->authService->clearIdentity();
         $this->flash->addMessage('danger', 'A problem occured storing user in database. <a href="%s" title="SSO logout">SSO Logout</a>');
         $this->logger->error('Problem inserting user form CAS in database', $identity->toArray());
         $this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]);
         return $res->withRedirect($this->userErrorRedirectUrl);
     }
     return $res;
 }
開發者ID:eellak,項目名稱:gredu_labs,代碼行數:35,代碼來源:CreateUser.php

示例2: crawlUrl

 public function crawlUrl()
 {
     $currentUrl = ['url' => $this->currentUrl, 'depth' => $this->currentDepth];
     do {
         $this->setCurrentUrl($currentUrl);
         if (!($doc = parent::crawlUrl())) {
             continue;
         }
         $username = $doc['.vcard-username']->text();
         $user = R::findOne('github', ' username = ? ', [$username]);
         //$user = R::find('github', " username=$username ");
         if (empty($user)) {
             $user = R::dispense('github');
             $now = time();
             $user->avatar = $doc['.vcard-avatar .avatar']->attr('src');
             $user->fullname = $doc['.vcard-fullname']->text();
             $user->username = $username;
             $user->email = $doc['.email']->text();
             $user->worksFor = $doc['.vcard-detail[itemprop=worksFor]']->text();
             $user->homeLocation = $doc['.vcard-detail[itemprop=homeLocation]']->text();
             $user->blogUrl = $doc['.vcard-detail[itemprop=url]']->text();
             $user->joinDate = $doc['.join-date']->attr('datetime');
             $user->url = $this->currentUrl;
             $user->createdAt = $now;
             $user->updatedAt = $now;
             if (R::store($user)) {
                 echo '存儲用戶', $username, '成功', PHP_EOL;
             } else {
                 echo '存儲用戶', $username, '失敗', PHP_EOL;
             }
         } else {
             echo '用戶', $username, '已經被存儲過了', PHP_EOL;
         }
     } while ($currentUrl = $this->nextUrl());
 }
開發者ID:CraryPrimitiveMan,項目名稱:php-spider,代碼行數:35,代碼來源:GitHub.php

示例3: save

 public function save()
 {
     if (!$this->emptyAttr('id')) {
         $menu = R::findOne('menu', 'id=?', [$this->getAttr('id')]);
     } else {
         $menu = R::dispense('menu');
     }
     $menu->name = $this->getAttr('name');
     $oldPicture = null;
     if (!$this->emptyAttr('picture') && $this->attr['picture']->uploaded) {
         $picture = $this->getAttr('picture');
         $picture->file_new_name_body = $this->generateName("menu_picture_");
         // $picture->image_resize = true;
         $picture->image_convert = 'jpeg';
         // $picture->image_x = 964;
         // $picture->image_y = 1024;
         // $picture->image_ratio_y = true;
         $picture->process('upload/');
         $oldPicture = $menu->picture;
         $menu->picture = $picture->file_dst_name;
     }
     $success = R::store($menu);
     if ($success) {
         if (!is_null($oldPicture)) {
             @unlink('upload/' . $oldPicture);
         }
     }
     return $success;
 }
開發者ID:nuiz,項目名稱:duragres,代碼行數:29,代碼來源:MenuForm.php

示例4: createSoftware

 public function createSoftware(array $data)
 {
     unset($data['id']);
     $software = R::dispense('software');
     $this->persistSoftware($software, $data);
     return $this->export($software);
 }
開發者ID:eellak,項目名稱:gredu_labs,代碼行數:7,代碼來源:SoftwareService.php

示例5: replace

 public function replace($content = '')
 {
     if (empty($this->name)) {
         throw new Exception('Blog post needs name before it can be saved');
     }
     $bean = $this->_bean;
     if ($bean === null) {
         $this->_bean = $bean = R::dispense('blog');
     }
     $bean->name = $this->name;
     $this->content = $bean->content = $content;
     $bean->edited = R::isoDateTime();
     $bean->created = $this->created ?: R::isoDateTime();
     $otherUserBean = App::user()->bean();
     $bean->user = $this->_user !== null ? $this->_user->bean() : $otherUserBean;
     $this->contributorIds[] = $otherUserBean->getID();
     $this->contributorIds = array_unique($this->contributorIds);
     $bean->contributorIds = implode(',', $this->contributorIds);
     if (!empty($this->publishedOn)) {
         $bean->publishedOn = R::isoDateTime($this->publishedOn);
     } else {
         $bean->publishedOn = null;
     }
     R::store($bean);
 }
開發者ID:Koohiisan,項目名稱:Enpowi,代碼行數:25,代碼來源:Post.php

示例6: createTeacher

 public function createTeacher(array $data)
 {
     unset($data['id']);
     $teacher = R::dispense('teacher');
     $this->persist($teacher, $data);
     return $this->export($teacher);
 }
開發者ID:eellak,項目名稱:gredu_labs,代碼行數:7,代碼來源:StaffService.php

示例7: createSchool

 public function createSchool(array $data)
 {
     $school = $this->importSchool(R::dispense('school'), $data);
     $school->created = time();
     R::store($school);
     return $this->exportSchool($school);
 }
開發者ID:eellak,項目名稱:gredu_labs,代碼行數:7,代碼來源:SchoolService.php

示例8: createLab

 public function createLab(array $data)
 {
     unset($data['id']);
     $lab = R::dispense('lab');
     $this->persist($lab, $data);
     return $this->exportLab($lab);
 }
開發者ID:eellak,項目名稱:gredu_labs,代碼行數:7,代碼來源:LabService.php

示例9: create

 /**
  * Add a job to the queue with name, unique, object
  * @param string $name
  * @param string $unique
  * @return int $res
  */
 protected function create($name, $uniqueid)
 {
     $bean = R::dispense($this->queue);
     $bean->name = $name;
     $bean->uniqueid = $uniqueid;
     $bean->done = 0;
     return R::store($bean);
 }
開發者ID:diversen,項目名稱:queue-simplex,代碼行數:14,代碼來源:queue.php

示例10: insertUser

 /**
  * @param Array $data
  * ['name','fullname','password']
  * @return string
  */
 public function insertUser($data)
 {
     $user = R::dispense('user');
     $user->name = $data['name'];
     $user->fullname = $data['fullname'];
     $user->hash = password_hash($data['password'], PASSWORD_DEFAULT);
     $id = R::store($user);
     return $id;
 }
開發者ID:neilmillard,項目名稱:slim3skel,代碼行數:14,代碼來源:User.php

示例11: editRota

 public function editRota(Request $request, Response $response, array $args)
 {
     $id = $this->authenticator->getIdentity();
     if (strtolower($id['name']) != 'admin') {
         $this->flash->addMessage('flash', 'Access Denied');
         return $response->withRedirect($this->router->pathFor('homepage'));
     }
     $name = $args['name'];
     if (empty($name)) {
         $this->flash->addMessage('flash', 'No rota specified');
         return $response->withRedirect($this->router->pathFor('rotas'));
     }
     if ($name != 'new') {
         $rota = R::findOrCreate('rotas', ['name' => $name]);
     } else {
         $rota = R::dispense('rotas');
     }
     if ($request->isPost()) {
         $data = $request->getParams();
         //$username = $request->getParam('username');
         $rota->import($data, 'name,fullname,title,comment');
         $rota->sharedUsersList = [];
         foreach ($data['users'] as $checkUserID) {
             $rotaUser = R::load('users', $checkUserID);
             $rota->sharedUsersList[] = $rotaUser;
         }
         $id = R::store($rota);
         try {
             $fieldtest = R::inspect($rota->name);
         } catch (\Exception $e) {
             //thaw for creation
             R::freeze(['users']);
             $rotaUser = R::load('users', 1);
             $rotaDay = R::findOrCreate($rota->name, ['day' => 29, 'month' => 2, 'year' => 2015]);
             $rotaUser = R::load('users', 1);
             $rotaDay->name = $rotaUser;
             $rotaDay->who = $rotaUser;
             $rotaDay->stamp = date("Y-m-d H:i:s");
             R::store($rotaDay);
             R::freeze(true);
         }
         $this->flash->addMessage('flash', "{$rota->name} updated");
         return $response->withRedirect($this->router->pathFor('rotas'));
     }
     $userList = R::findAll('users');
     $data = $rota->export();
     $data['userList'] = $userList;
     $users = [];
     $userRota = $rota->sharedUsersList;
     foreach ($userRota as $userCheck) {
         $users[$userCheck->id] = 'checked';
     }
     $data['userCheck'] = $users;
     $this->view->render($response, 'rota.twig', $data);
     return $response;
 }
開發者ID:aodkrisda,項目名稱:oncallslim,代碼行數:56,代碼來源:RotaAction.php

示例12: getCurrenciesFromJsonrates

 /**
  * @throws \RedBeanPHP\RedException
  */
 protected static function getCurrenciesFromJsonrates()
 {
     $data = json_decode(file_get_contents('http://jsonrates.com/currencies.json', true));
     foreach ($data as $code => $name) {
         $currency = RedBean::dispense('currency');
         $currency->code = $code;
         $currency->name = $name;
         RedBean::store($currency);
     }
 }
開發者ID:pashukhin,項目名稱:traider_test,代碼行數:13,代碼來源:TraiderApi.php

示例13: store

function store()
{
    $email = R::dispense('email');
    foreach (\app\run('input', 'keys', 'post') as $key) {
        $element = str_replace('-', '_', $key);
        $email->{$element} = \app\run('input', 'post', $key);
    }
    R::store($email);
    return null;
}
開發者ID:draganescu,項目名稱:sibip-commands,代碼行數:10,代碼來源:store.php

示例14: testGetDetailsCustom

 public function testGetDetailsCustom()
 {
     $details = R::dispense('detail');
     $details->desc = 'A test blog.';
     $details->image = 'some url';
     R::store($details);
     $response = $this->details->getDetails(new RequestMock(), new ResponseMock(), null);
     $this->assertEquals('success', $response->status);
     $this->assertEquals('SMPLog', $response->data[0]['name']);
     $this->assertEquals('A test blog.', $response->data[0]['desc']);
 }
開發者ID:kiswa,項目名稱:SMPLog,代碼行數:11,代碼來源:DetailsTest.php

示例15: save

 public function save()
 {
     $account = R::dispense('account');
     $account->created_at = date('Y-m-d H:i:s');
     $account->email = empty($this->attr['email']) ? null : $this->attr['email'];
     $account->token = bin2hex(openssl_random_pseudo_bytes(16));
     if (R::store($account)) {
         return $account;
     } else {
         return false;
     }
 }
開發者ID:nuiz,項目名稱:duragres,代碼行數:12,代碼來源:RegisterForm.php


注:本文中的RedBeanPHP\R::dispense方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。