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


PHP Slim::error方法代码示例

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


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

示例1: function

$app->configureMode('development', function () use($app) {
    $app->config(array('debug' => true));
});
$app->configureMode('production', function () use($app) {
    error_reporting(0);
    $app->notFound(function () use($app) {
        $page = new ErrorController(404);
        $page->render();
    });
    $app->error(function (Exception $e) use($app) {
        $app->response()->status(500);
        if (!$app->request()->isAjax()) {
            $page = new ErrorController(500);
            $page->render();
        }
        $app->stop();
        if (file_exists(BASE_DIR . '/.gbemail')) {
            foreach (explode('\\n', file_get_contents(BASE_DIR . '/.gbemail')) as $email) {
                mail(trim($email), "GetchaBooks Error", get_error_message($e));
            }
        }
    });
});
$app->hook('slim.before', function () use($app) {
    global $referrers;
    $request = $app->request();
    define('BASE_URL', $request->getUrl() . $request->getRootUri() . '/');
    define('CURRENT_URL', $request->getUrl() . $request->getPath());
    define('MOBILE_DEVICE', strpos(strtolower($request->getUserAgent()), 'mobile') !== false);
    // remove extra slashes
    $path = $request->getPath();
开发者ID:therealchiko,项目名称:getchabooks,代码行数:31,代码来源:index.php

示例2: testSlimError

 /**
  * Test Slim returns 500 response if error thrown within Slim app
  *
  * Pre-conditions:
  * You have initialized a Slim app with a custom Error handler with
  * an accessible route that calls Slim::error().
  *
  * Post-conditions:
  * The response status will be 500
  */
 public function testSlimError() {
     $this->setExpectedException('Slim_Exception_Stop');
     Slim::init();
     Slim::get('/', function () { Slim::error(); });
     Slim::run();
     $this->assertEquals(Slim::response()->status(), 500);
 }
开发者ID:ntdt,项目名称:Slim,代码行数:17,代码来源:SlimTest.php

示例3: testErrorHandlerUsesCurrentResponseObject

 /**
  * Test custom error handler uses existing Response object
  */
 public function testErrorHandlerUsesCurrentResponseObject()
 {
     $s = new Slim(array('debug' => false));
     $s->error(function (Exception $e) use($s) {
         $r = $s->response();
         $r->status(503);
         $r->write('Foo');
         $r['X-Powered-By'] = 'Slim';
         echo 'Bar';
     });
     $s->get('/bar', function () {
         throw new Exception('Foo');
     });
     $s->call();
     list($status, $header, $body) = $s->response()->finalize();
     $this->assertEquals(503, $status);
     $this->assertEquals('FooBar', $body);
     $this->assertEquals('Slim', $header['X-Powered-By']);
 }
开发者ID:rs3d,项目名称:Slimplr,代码行数:22,代码来源:SlimTest.php

示例4: Slim

ob_start("ob_gzhandler");
header('Content-type: application/json');
require_once "../include_me.php";
require 'Slim/Slim.php';
$app = new Slim();
/**
 * Set Custom 404 page when an API method is not found
 */
$app->notFound(function () use($app) {
    $app->render("api404.html");
});
/**
 * Set Custom Error Page. No sensetive information should be displayed to the user
 */
$app->error(function () use($app) {
    // log error
    //$app -> render("apiError.html");
});
/**
 * REST Methods
 */
$app->get('/teacher/', function () use($teacherModel) {
    $result = $teacherModel->get();
    echo json_encode($result);
});
$app->get('/course/', function () use($courseModel) {
    $result = $courseModel->get();
    echo json_encode($result);
});
$app->get('/teacherByCourse/:id/', function ($id) use($teacherModel) {
    $result = $teacherModel->getByCourseId($id);
    echo json_encode($result);
开发者ID:RadoRado,项目名称:Fmi-Feedback,代码行数:32,代码来源:index.php

示例5: testSlimError

 /**
  * Test default and custom error handlers
  *
  * Pre-conditions:
  * One app calls the user-defined error handler directly;
  * One app triggers a generic PHP error;
  * One app has debugging disabled, throws Exception to invoke error handler indirectly;
  *
  * Post-conditions:
  * All apps' response status is 500;
  * App with debugging disabled catches ErrorException in user-defined error handler;
  */
 public function testSlimError()
 {
     $app1 = new Slim();
     $app1->get('/', function () use($app1) {
         $app1->error();
     });
     $app2 = new Slim();
     $app2->get('/', function () {
         trigger_error('error');
     });
     $app3 = new Slim(array('debug' => false));
     $app3->error(function ($e) {
         if ($e instanceof Exception) {
             echo get_class($e);
         }
     });
     $app3->get('/', function () {
         $result = 1 / 0;
     });
     ob_start();
     $app1->run();
     $app1Out = ob_get_clean();
     ob_start();
     $app2->run();
     $app2Out = ob_get_clean();
     ob_start();
     $app3->run();
     $app3Out = ob_get_clean();
     $this->assertEquals(500, $app1->response()->status());
     $this->assertEquals(500, $app2->response()->status());
     $this->assertEquals('ErrorException', $app3Out);
 }
开发者ID:inscriptionweb,项目名称:lebonmail,代码行数:44,代码来源:SlimTest.php

示例6: array

                if (!isset($post['of']) || trim($post['of']) == "" || $post['of'] == 0 || $post['of'] == "0" || !is_numeric($post['of'])) {
                    $of = "?";
                } else {
                    $of = $post['of'];
                }
                if ($teams == "?" && $of == "?") {
                    $params['teams'] = App::teamsForEvent($id, "2", "?");
                } else {
                    $params['teams'] = App::teamsForEvent($id, $teams, $of);
                }
            }
        }
    }
    $params['id'] = $id;
    $params['errors'] = array();
    $app->render('app.tpl', $params);
})->via('GET', 'POST');
$app->get('/error/(:code)/', function ($code) use($app) {
    if (isset($code) && $code != null) {
        $app->render('error.tpl', array('code' => $code));
    } else {
        $app->render('error.tpl');
    }
});
$app->notFound(function () use($app) {
    $app->redirect("/error/404/");
});
$app->error(function (Exception $e) use($app) {
    $app->notFound();
});
$app->run();
开发者ID:ryanj,项目名称:The-Event-Day,代码行数:31,代码来源:index.php

示例7: testErrorHandlerReceivesException

 /**
  * Test error handler receives Exception as argument
  *
  * Pre-conditions:
  * Custom error handler defined;
  * Invoked app route throws Exception;
  *
  * Post-conditions:
  * Response status is 500;
  * Error handler's argument is the thrown Exception
  */
 public function testErrorHandlerReceivesException()
 {
     $this->expectOutputString('ErrorException');
     $app = new Slim(array('debug' => false));
     $app->error(function ($e) {
         if ($e instanceof Exception) {
             echo get_class($e);
         }
     });
     $app->get('/', function () {
         $result = 1 / 0;
     });
     $app->run();
     $this->assertEquals(500, $app->response()->status());
 }
开发者ID:Robert-Xie,项目名称:php-framework-benchmark,代码行数:26,代码来源:SlimTest.php

示例8: function

$app->get('/check', function () use($app) {
    $url = trim($app->request()->params('url'));
    if ($url === 'random') {
        $url = get_random_url();
    }
    // Normalize URL to include "http://" prefix.
    $url2 = parse_url($url);
    if (!isset($url2['scheme'])) {
        $url = "http://{$url2['path']}";
    }
    $data['url'] = $url;
    $refresh = $app->request()->params('refresh') === '1' ? true : false;
    $http = new Http();
    list($header, $body) = $http->get($url, $refresh);
    if (!$header) {
        $app->error(new Exception($body));
    }
    $xml_data = array('Server Information' => 'servers.xml', 'Content Delivery Network' => 'cdn.xml', 'Advertising' => 'ads.xml', 'Analytics and Tracking' => 'trackings.xml', 'CMS' => 'cms.xml', 'Web Portals' => 'portals.xml', 'CSS Frameworks' => 'css.xml', 'Chart Libraries' => 'charts.xml', 'Frameworks' => 'frameworks.xml', 'Javascript Libraries' => 'js.xml', 'Javascript Frameworks' => 'jsframeworks.xml', 'Widgets' => 'widgets.xml', 'Audio/Video' => 'av.xml', 'Aggregation' => 'aggregation.xml', 'Payments' => 'payments.xml', 'Document Info' => 'document.xml', 'Meta Tags' => 'meta.xml');
    $site = new Site($header, $body);
    $results = array();
    $mt = microtime(true);
    foreach ($xml_data as $title => $xml) {
        $result = $site->analyze(DATA_DIR . $xml);
        if (!empty($result)) {
            $results[$title] = $result;
        }
    }
    $data['analysis_time'] = sprintf("%.02f", microtime(true) - $mt);
    $data['total_time'] = sprintf("%.02f", $http->total_time);
    $data['speed_download'] = format_filesize($http->speed_download);
    $data['size_download_gzip'] = format_filesize($http->size_download_gzip);
开发者ID:prakashnsm,项目名称:siteanalyzer,代码行数:31,代码来源:index.php

示例9: getEmployees

<?php

/*
 * RESTFul API for an employee directory application. Sandbox for offline-sync experimentation. Maintain a session-based
 * and updatable employee list that mimics a real-life database-powered backend while enabling multiple users to
 * experiment with CRUD operations on their isolated data set without compromising the integrity of a central database.
 */
require 'Slim/Slim.php';
session_start();
if (!isset($_SESSION['employees'])) {
    $_SESSION['employees'] = array((object) array("id" => 1, "firstName" => "John", "lastName" => "Smith", "title" => "CEO", "officePhone" => "617-321-4567", "lastModified" => "2008-01-01 00:00:00", "deleted" => false), (object) array("id" => 2, "firstName" => "Lisa", "lastName" => "Taylor", "title" => "VP of Marketing", "officePhone" => "617-522-5588", "lastModified" => "2011-06-01 01:00:00", "deleted" => false), (object) array("id" => 3, "firstName" => "James", "lastName" => "Jones", "title" => "VP of Sales", "officePhone" => "617-589-9977", "lastModified" => "2009-08-01 16:30:24", "deleted" => false), (object) array("id" => 4, "firstName" => "Paul", "lastName" => "Wong", "title" => "VP of Engineering", "officePhone" => "617-245-9785", "lastModified" => "2012-05-01 08:22:10", "deleted" => false), (object) array("id" => 5, "firstName" => "Alice", "lastName" => "King", "title" => "Architect", "officePhone" => "617-744-1177", "lastModified" => "2012-02-10 22:58:37", "deleted" => false), (object) array("id" => 6, "firstName" => "Jen", "lastName" => "Brown", "title" => "Software Engineer", "officePhone" => "617-568-9863", "lastModified" => "2010-01-15 11:17:45", "deleted" => false), (object) array("id" => 7, "firstName" => "Amy", "lastName" => "Garcia", "title" => "Software Engineer", "officePhone" => "617-327-9966", "lastModified" => "2011-07-03 14:24:50", "deleted" => false), (object) array("id" => 8, "firstName" => "Jack", "lastName" => "Green", "title" => "Software Engineer", "officePhone" => "617-565-9966", "lastModified" => "2012-04-28 10:25:56", "deleted" => false));
}
$app = new Slim(array('debug' => false));
$app->error(function (Exception $e) use($app) {
    echo $e->getMessage();
});
$app->get('/employees', 'getEmployees');
$app->post('/employees', 'addEmployee');
$app->put('/employees/:id', 'updateEmployee');
$app->delete('/employees/:id', 'deleteEmployee');
$app->run();
function getEmployees()
{
    if (isset($_GET['modifiedSince'])) {
        getModifiedEmployees($_GET['modifiedSince']);
        return;
    }
    $employees = $_SESSION['employees'];
    $result = array();
    foreach ($employees as $employee) {
        if (!$employee->deleted) {
开发者ID:jeffolen4,项目名称:offline-sync,代码行数:31,代码来源:index.php


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