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


PHP Slim::patch方法代码示例

本文整理汇总了PHP中Slim\Slim::patch方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::patch方法的具体用法?PHP Slim::patch怎么用?PHP Slim::patch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim\Slim的用法示例。


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

示例1: addRoutesFromMeta

 private function addRoutesFromMeta(Slim $application, ClassMetadata $meta, Controller $controller)
 {
     $entitiesRoute = $this->getEntitiesRoute($meta);
     // Fetch entities route
     $application->get($entitiesRoute, function () use($meta, $controller) {
         $controller->getEntities($meta);
     });
     // Create entity
     $application->post($entitiesRoute, function () use($meta, $controller) {
         $controller->createEntity($meta);
     });
     $entityRoute = $this->getEntityRoute($meta, $entitiesRoute);
     // Get entity
     $application->get($entityRoute, function () use($meta, $controller) {
         $controller->getEntity($meta, func_get_args());
     });
     // Update entity
     $application->put($entityRoute, function () use($meta, $controller) {
         $controller->updateEntity($meta, func_get_args());
     });
     // Patch entity
     $application->patch($entityRoute, function () use($meta, $controller) {
         $controller->patchEntity($meta, func_get_args());
     });
     // Delete entity
     $application->delete($entityRoute, function () use($meta, $controller) {
         $controller->deleteEntity($meta, func_get_args());
     });
     // Handling associated entities
     foreach ($meta->getAssociationMappings() as $aName => $aData) {
         $aTargetClass = $meta->getAssociationTargetClass($aName);
         $aMeta = $this->getEntityMeta($aTargetClass);
         $aEntitiesRoute = $entityRoute . '/' . $aName;
         // Create associated entity
         // allow to create entity and link source together
         // POST /articles/1/tags will fetch article 1, create tag entity and
         // associate it to article 1
         $application->post($aEntitiesRoute, function () use($meta, $aMeta, $controller, $aData) {
             $controller->createEntity($aMeta, $aData['fieldName'], $meta, func_get_args());
         });
         // List associated entities
         $application->get($aEntitiesRoute, function () use($meta, $controller, $aData) {
             $controller->getAssociatedEntities($aData['fieldName'], $meta, func_get_args());
         });
         // Associate two entities
         // POST /articles/1/tags/2 will associate article 1 to tag 2
         $aEntityRoute = $this->getEntityRoute($aMeta, $aEntitiesRoute);
         $application->post($aEntityRoute, function () use($meta, $aMeta, $controller, $aData) {
             $controller->associateEntities($aMeta, $aData['fieldName'], $meta, func_get_args());
         });
     }
     return $application;
 }
开发者ID:petitchevalroux,项目名称:newswatcher-api,代码行数:53,代码来源:RestDoctrineRouter.php

示例2: Slim

}
$app = new Slim(['mode' => $slimMode, 'debug' => $debug, 'view' => $di->layoutHtml]);
// Allow to decode json request body
$app->add(new ContentTypesMiddleware());
$app->get('/auth/login', function () use($app) {
    $app->render('auth/login');
});
$app->get('/auth/twitter/login', function () {
    AuthTwitterController::getInstance()->login();
});
$app->get('/auth/twitter/callback', function () {
    AuthTwitterController::getInstance()->callback();
});
$app->get('/auth/logout', function () {
    AuthentifierController::getInstance()->logout();
});
$app->get('/home', function () {
    HomeController::getInstance()->home();
});
$app->get('/api/articles', function () {
    ArticlesController::getInstance()->get();
});
$app->patch('/api/articles/:id', function ($id) {
    ArticlesController::getInstance()->update($id);
});
$app->notFound(function () use($app) {
    $status = 404;
    $app->response->setStatus($status);
    $app->render('error', ['errno' => $status, 'message' => $app->response->getMessageForCode($status)]);
});
return $app;
开发者ID:petitchevalroux,项目名称:newswatcher-www,代码行数:31,代码来源:slim.php

示例3: function

| "/emojis" get all emoji from the database
*/
$app->get('/emojis', function () use($emojiController) {
    $emojiController->all();
});
/*
| "/emojis" create new emoji
*/
$app->put('/emojis', $authenticated, function () use($emojiController) {
    $emojiController->addEmoji();
});
/*
| "/emojis" update emoji
*/
$app->patch('/emojis/:id', $authenticated, function ($id) use($emojiController) {
    $emojiController->updateEmoji($id);
});
/*
| "/emojis" find an emoji by id
| POST method
*/
$app->get('/emojis/:id', function ($id) use($emojiController) {
    $emojiController->findEmoji($id);
});
/*
| "/emojis/:id" find and delete an emoji by id
| DELETE method
*/
$app->delete('/emojis/:id', function ($id) use($emojiController) {
    $emojiController->deleteEmoji($id);
});
开发者ID:emeka-osuagwu,项目名称:sweetemoji,代码行数:31,代码来源:index.php

示例4: function

        echo '{"error":{"text":' . $e->getMessage() . '}}';
    }
});
/**
 * Route to partially update an emoji.
 */
$app->patch('/emojis/:id', function ($id) use($app) {
    try {
        $app->response()->headers("Content-Type", "application/json");
        $authHeader = $app->request->headers->get('Authorization');
        $decodedToken = Reusable::tokenVerify($authHeader);
        if ($decodedToken) {
            $emoji = json_decode($app->request->getBody(), true);
            $emojiUpdate = Emoji::with('user')->where('id', $id)->first();
            if ($emojiUpdate->user->token !== 1) {
                echo json_encode(array("status" => "Bad request", "message" => "Log in to partially update the emoji!"));
            } else {
                $emojiUpdate->update($emoji);
                echo json_encode(array("status" => "success", "message" => "Emoji partially updated!"));
            }
        }
    } catch (\PDOException $e) {
        echo '{"error":{"text":' . $e->getMessage() . '}}';
    }
});
/**
 * Route to delete an emoji.
 */
$app->delete('/emojis/:id', function ($id) use($app) {
    try {
        $app->response()->headers("Content-Type", "application/json");
开发者ID:andela-sachungo,项目名称:php-checkpoints,代码行数:31,代码来源:index.php


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