当前位置: 首页>>代码示例>>PHP>>正文


PHP Rest类代码示例

本文整理汇总了PHP中Rest的典型用法代码示例。如果您正苦于以下问题:PHP Rest类的具体用法?PHP Rest怎么用?PHP Rest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Rest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * First pass of the spec: parse and stop execution on errors
  * @todo: introduce ValidationException
  *
  * @param  SpecRest $restSpec
  * @return void
  */
 public function validate(Rest $restSpec)
 {
     $apiSpec = $restSpec->getApiSpecs();
     if (empty($apiSpec)) {
         throw new \RuntimeException('No API spec provided');
     }
     foreach ($apiSpec as $apiSpec) {
         foreach ($apiSpec->getUrlSpecs() as $urlSpec) {
             $useCases = $urlSpec->getUseCases();
             if (!$useCases) {
                 throw new \RuntimeException('You have to specify use cases inside the URL specificetion');
             }
             foreach ($useCases as $urlUseCaseSpec) {
                 if (!$urlUseCaseSpec->getRequest()) {
                     throw new \RuntimeException('You have to add request specification using givenRequest() function');
                 }
                 if (!$urlUseCaseSpec->getExpectedResponseSpec()) {
                     throw new \RuntimeException('You have to specify expected response using expectResponse() function');
                 }
                 if ($urlUseCaseSpec->isATemplate() && !$urlUseCaseSpec->getExampleParameters()) {
                     throw new \RuntimeException('To use an URL template you have to provide example parameters to call the URL with.');
                 }
                 if ($exampleParams = $urlUseCaseSpec->getExampleParameters()) {
                     foreach ($exampleParams as $name => $value) {
                         $placeholder = $urlUseCaseSpec->buildParameterPlaceholder($name);
                         if (strpos($urlUseCaseSpec->getUrl(), $placeholder) === false) {
                             throw new \RuntimeException(sprintf('You specified example parameter, but the placeholder "%s" for it is missing in your URL', $placeholder));
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:talkrz,项目名称:rest-spec,代码行数:41,代码来源:Validator.php

示例2: actionClearInitDataPeopleAll

 public function actionClearInitDataPeopleAll()
 {
     //inject Data brute d'une liste de Person avec Id
     $import = Admin::initMultipleModuleData($this->module->id, "personNetworkingAll", true, true, true);
     Rest::json($import);
     Yii::app()->end();
 }
开发者ID:Biocoder2600,项目名称:communecter,代码行数:7,代码来源:PersonController.php

示例3: run

 public function run()
 {
     $events = array();
     $organization = Organization::getPublicData($id);
     if (isset($organization["links"]["events"])) {
         foreach ($organization["links"]["events"] as $key => $value) {
             $event = Event::getPublicData($key);
             $events[$key] = $event;
         }
     }
     foreach ($organization["links"]["members"] as $newId => $e) {
         if ($e["type"] == Organization::COLLECTION) {
             $member = Organization::getPublicData($newId);
         } else {
             $member = Person::getPublicData($newId);
         }
         if (isset($member["links"]["events"])) {
             foreach ($member["links"]["events"] as $key => $value) {
                 $event = Event::getPublicData($key);
                 $events[$key] = $event;
             }
         }
     }
     Rest::json($events);
 }
开发者ID:CivicTechFR,项目名称:PixelHumain,代码行数:25,代码来源:GetCalendarAction.php

示例4: run

 public function run($eventId)
 {
     if (isset(Yii::app()->session["userId"])) {
         Event::delete($eventId, Yii::app()->session["userId"]);
     }
     Rest::json(array('result' => true, "msg" => Yii::t("event", "Event removed")));
 }
开发者ID:CivicTechFR,项目名称:PixelHumain,代码行数:7,代码来源:DeleteAction.php

示例5: run

 public function run()
 {
     $whereGeo = array();
     //$this->getGeoQuery($_POST);
     $where = array('geo' => array('$exists' => true));
     $where = array_merge($where, $whereGeo);
     $events = PHDB::find(PHType::TYPE_EVENTS, $where);
     foreach ($events as $event) {
         //dans le cas où un événement n'a pas de position geo,
         //on lui ajoute grace au CP
         //il sera visible sur la carte au prochain rechargement
         if (!isset($event["geo"])) {
             $cp = $event["location"]["address"]["addressLocality"];
             $queryCity = array("cp" => strval(intval($cp)), "geo" => array('$exists' => true));
             $city = Yii::app()->mongodb->cities->findOne($queryCity);
             //->limit(1)
             if ($city != null) {
                 $newPos = array('geo' => array("@type" => "GeoCoordinates", "longitude" => floatval($city['geo']['coordinates'][0]), "latitude" => floatval($city['geo']['coordinates'][1])), 'geoPosition' => $city['geo']);
                 Yii::app()->mongodb->events->update(array("_id" => $event["_id"]), array('$set' => $newPos));
             }
         }
     }
     $events["origine"] = "ShowLocalEvents";
     Rest::json($events);
     Yii::app()->end();
 }
开发者ID:CivicTechFR,项目名称:PixelHumain,代码行数:26,代码来源:ShowLocalEventsAction.php

示例6: run

 public function run()
 {
     //récupère seulement les citoyens qui ont un nom et une position géo
     $users = PHDB::find(PHType::TYPE_CITOYEN);
     Rest::json($users);
     Yii::app()->end();
 }
开发者ID:Koulio,项目名称:pixelhumain,代码行数:7,代码来源:ShowCitoyensAction.php

示例7: run

 /**
  * Update an information field for an organization
  */
 public function run()
 {
     $organizationId = "";
     $res = array("result" => false, "msg" => Yii::t("common", "Something went wrong!"));
     if (!empty($_POST["pk"])) {
         $organizationId = $_POST["pk"];
     } else {
         if (!empty($_POST["id"])) {
             $organizationId = $_POST["id"];
         }
     }
     if ($organizationId != "") {
         if (!empty($_POST["name"]) && !empty($_POST["value"])) {
             $organizationFieldName = $_POST["name"];
             $organizationFieldValue = $_POST["value"];
             try {
                 Organization::updateOrganizationField($organizationId, $organizationFieldName, $organizationFieldValue, Yii::app()->session["userId"]);
                 $res = array("result" => true, "msg" => Yii::t("organisation", "The organization has been updated"), $organizationFieldName => $organizationFieldValue);
             } catch (CTKException $e) {
                 $res = array("result" => false, "msg" => $e->getMessage(), $organizationFieldName => $organizationFieldValue);
             }
         }
     }
     Rest::json($res);
 }
开发者ID:CivicTechFR,项目名称:PixelHumain,代码行数:28,代码来源:UpdateFieldAction.php

示例8: run

 /**
  * Save a job
  * @return an array with result and message json encoded
  */
 public function run()
 {
     $controller = $this->getController();
     //insert a new job
     if (empty($_POST["pk"])) {
         foreach ($_POST as $fieldName => $fieldValue) {
             $collectionName = $controller->getCollectionFieldName($fieldName);
             $job[$collectionName] = $fieldValue;
         }
         $res = Job::insertJob($job);
         if ($res["result"]) {
             return Rest::json(array("msg" => "insertion ok ", "id" => $res["id"], "job" => $res["job"]));
         }
         //update an existing job
     } else {
         $jobId = $_POST["pk"];
         if (!empty($_POST["name"]) && !empty($_POST["value"])) {
             $jobFieldName = $_POST["name"];
             $jobFieldValue = $_POST["value"];
             $collectionName = $controller->getCollectionFieldName($jobFieldName);
             Job::updateJobField($jobId, $collectionName, $jobFieldValue, Yii::app()->session["userId"]);
         } else {
             return Rest::json(array("result" => false, "msg" => Yii::t("common", "Uncorrect request")));
         }
     }
     return Rest::json(array("result" => true, "msg" => Yii::t("job", "Your job offer has been updated with success"), $jobFieldName => $jobFieldValue));
 }
开发者ID:CivicTechFR,项目名称:PixelHumain,代码行数:31,代码来源:SaveAction.php

示例9: run

 public function run($id)
 {
     $controller = $this->getController();
     //get The job Id
     if (empty($id)) {
         throw new CTKException(Yii::t("job", "The job posting id is mandatory to retrieve the job posting !"));
     }
     if (empty($_POST["mode"])) {
         $mode = "view";
     } else {
         $mode = $_POST["mode"];
     }
     if ($mode == "insert") {
         $job = array();
         $controller->title = Yii::t("job", "New Job Offer");
         $controller->subTitle = Yii::t("job", "Fill the form");
     } else {
         $job = Job::getById($id);
         $controller->title = $job["title"];
         $controller->subTitle = isset($job["description"]) ? $job["description"] : (isset($job["type"]) ? "Type " . $job["type"] : "");
     }
     $tags = json_encode(Tags::getActiveTags());
     $organizations = Authorisation::listUserOrganizationAdmin(Yii::app()->session["userId"]);
     $controller->pageTitle = Yii::t("job", "Job Posting");
     Rest::json(array("result" => true, "content" => $controller->renderPartial("jobSV", array("job" => $job, "tags" => $tags, "organizations" => $organizations, "mode" => $mode), true)));
 }
开发者ID:CivicTechFR,项目名称:PixelHumain,代码行数:26,代码来源:PublicAction.php

示例10: run

 public function run($name)
 {
     if ($name) {
         $list = Lists::getListByName($name);
     }
     Rest::json(array("result" => true, "list" => $list));
 }
开发者ID:CivicTechFR,项目名称:PixelHumain,代码行数:7,代码来源:GetListByNameAction.php

示例11: run

 public function run($type, $id, $contentKey = null, $user)
 {
     if (isset($_FILES['avatar'])) {
         $type = trim($type);
         $folder = str_replace(DIRECTORY_SEPARATOR, "/", DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR);
         $pathImage = $this->processImage($_FILES['avatar'], $id, $type);
         if ($pathImage) {
             $params = array();
             $params["id"] = $id;
             $params["type"] = $type;
             $params['folder'] = $folder;
             $params['moduleId'] = Yii::app()->controller->module->id;
             $params['name'] = $pathImage["name"];
             $params['doctype'] = "image";
             $params['size'] = $pathImage["size"][0] * $pathImage["size"][1] / 1000;
             $params['author'] = $user;
             $params['category'] = array();
             $params['contentKey'] = $contentKey;
             $result = Document::save($params);
             //Profile to check
             $urlBdd = str_replace(DIRECTORY_SEPARATOR, "/", DIRECTORY_SEPARATOR . "upload" . DIRECTORY_SEPARATOR . Yii::app()->controller->module->id . $folder . $pathImage["name"]);
             Document::setImagePath($id, $type, $urlBdd, $contentKey);
             $newImage = Document::getById($result["id"]);
         }
         $res = array('result' => true, 'msg' => 'The picture was uploaded', 'imagePath' => $urlBdd, "id" => $result["id"], "image" => $newImage);
         Rest::json($res);
         Yii::app()->end();
     }
 }
开发者ID:Koulio,项目名称:pixelhumain,代码行数:29,代码来源:SaveUserImagesAction.php

示例12: run

 public function run()
 {
     $res = array();
     if (Yii::app()->session["userId"]) {
         $email = $_POST["email"];
         $name = $_POST['name'];
         //if exists login else create the new user
         if (PHDB::findOne(PHType::TYPE_CITOYEN, array("email" => $email))) {
             //udate the new app specific fields
             $newInfos = array();
             $newInfos['email'] = (string) $email;
             $newInfos['name'] = (string) $name;
             if (isset($_POST['survey'])) {
                 $newInfos['survey'] = $_POST['survey'];
             }
             if (isset($_POST['message'])) {
                 $newInfos['message'] = (string) $_POST['message'];
             }
             if (isset($_POST['type'])) {
                 $newInfos['type'] = $_POST['type'];
             }
             if (isset($_POST['tags']) && !empty($_POST['tags'])) {
                 $newInfos['tags'] = explode(",", $_POST['tags']);
             }
             if (isset($_POST['cp'])) {
                 $newInfos['cp'] = explode(",", $_POST['cp']);
             }
             if (isset($_POST['urls'])) {
                 $newInfos['urls'] = $_POST['urls'];
             }
             $newInfos['created'] = time();
             //specific application routines
             if (isset($_POST["app"])) {
                 $appKey = $_POST["app"];
                 if ($app = PHDB::findOne(PHType::TYPE_APPLICATIONS, array("key" => $appKey))) {
                     //when registration is done for an application it must be registered
                     $newInfos['applications'] = array($appKey => array("usertype" => isset($_POST['type']) ? $_POST['type'] : $_POST['app']));
                     //check for application specifics defined in DBs application entry
                     if (isset($app["moderation"])) {
                         $newInfos['applications'][$appKey][SurveyType::STATUS_CLEARED] = false;
                         //TODO : set a Notification for admin moderation
                     }
                     $res['applicationExist'] = true;
                 } else {
                     $res['applicationExist'] = false;
                 }
             }
             PHDB::update(PHType::TYPE_PROJECTS, array("name" => $name), array('$set' => $newInfos), array('upsert' => true));
             $res['result'] = true;
             $res['msg'] = $this->id . "Saved";
         } else {
             $res = array('result' => false, 'msg' => "user doen't exist");
         }
     } else {
         $res = array('result' => false, 'msg' => 'something somewhere went terribly wrong');
     }
     Rest::json($res);
     Yii::app()->end();
 }
开发者ID:Koulio,项目名称:pixelhumain,代码行数:59,代码来源:SaveAction.php

示例13: run

 public function run()
 {
     //affiche les villes de plus de 100 000 habitants
     $query = array('habitants' => array('$gt' => 100000));
     $cities = iterator_to_array(Yii::app()->mongodb->cities->find($query));
     Rest::json($cities);
     Yii::app()->end();
 }
开发者ID:Koulio,项目名称:pixelhumain,代码行数:8,代码来源:ShowCitiesAction.php

示例14: run

 public function run()
 {
     $email = Yii::app()->session["userEmail"];
     $user = Yii::app()->mongodb->citoyens->findOne(array("email" => $email));
     $city = Yii::app()->mongodb->cities->findOne(array("cp" => $user['cp']));
     Rest::json(array('user' => $user, 'city' => $city));
     Yii::app()->end();
 }
开发者ID:Koulio,项目名称:pixelhumain,代码行数:8,代码来源:GetCitoyenConnectedAction.php

示例15: run

 public function run()
 {
     //TODO $res = Citoyen::addNode( "applications.".$_POST['app'].".isAdmin" ,true , $_POST['id']  );
     //TODO update application sadmin array
     $res = array('result' => true);
     Rest::json($res);
     Yii::app()->end();
 }
开发者ID:Koulio,项目名称:pixelhumain,代码行数:8,代码来源:AddAppAdminAction.php


注:本文中的Rest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。