本文整理汇总了PHP中exception函数的典型用法代码示例。如果您正苦于以下问题:PHP exception函数的具体用法?PHP exception怎么用?PHP exception使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exception函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display
/**
* 加载模板
* @param null $template
*/
public function display($template = null, $isPath = false)
{
//$template = isset($template)?self::$routeUrl['module']."/".self::$routeUrl['controller']."_".$template.'.html':self::$routeUrl['module']."_".self::$routeUrl['controller'].'.html';
//m:c:a or index
//TODO 代码重用性 ↓↓↓↓↓↓↓
if (is_array(self::$assignData)) {
foreach (self::$assignData as $key => $value) {
self::$view->assign($key, $value);
}
}
//TODO 代码重用性 ↑↑↑↑↑↑↑
//如果直接 :分割 传入路径 不解析模型 应用于common
if ($isPath) {
self::$view->display($template);
exit;
}
if (isset($template)) {
$pos = strpos($template, ":");
if ($pos) {
$tArr = explode(":", $template);
if (count($tArr) == 3) {
$template = $tArr[0] . "/" . $tArr[1] . "_" . $tArr[2];
} else {
return exception($template . "格式错误,必须为 M:C:A!");
}
} else {
$template = self::$routeUrl['module'] . "/" . self::$routeUrl['controller'] . "_" . $template;
}
} else {
$template = self::$routeUrl['module'] . "/" . self::$routeUrl['controller'] . "_" . self::$routeUrl['action'];
}
self::$view->display($template);
}
示例2: init
public static function init($date, $form)
{
$dateArray = array();
$safeFilter = new safeFilter();
foreach ($date as $k => $v) {
if (isset($form[$k]['datatype'])) {
$dataType = $form[$k]['datatype'];
if (array_key_exists($dataType, self::$type)) {
//直接匹配验证
if (!preg_match(self::$type[$dataType], $date[$k])) {
return exception("不合法的数据:['{$date[$k]}'']");
}
} else {
if (array_key_exists(preg_replace("/\\d+/is", "?", $dataType), self::$type)) {
//正则匹配
$key = preg_replace("/\\d+/is", "?", $dataType);
//获取数值
preg_match("/.+(\\d)+-(\\d+)/", $dataType, $matchAll);
//组装正则
$preg = sprintf(self::$type[$key], $matchAll[1], $matchAll[2]);
if (!preg_match($preg, $date[$k])) {
return exception("不合法的数据:['{$date[$k]}'']");
}
} elseif (preg_match("/^\\/.*\\/\$/", $dataType)) {
//直接正则
if (!preg_match($dataType, $date[$k])) {
return exception("不合法的数据:['{$date[$k]}'']");
}
}
}
}
}
return $date;
}
示例3: set
/**
* 设置数据
*
* @param int|string $id
* @param string $key
* @param $name
*/
protected function set($id, $key = null, $name = null)
{
if (is_null($key) && is_null($name)) {
exception('请添加正确状态表数据');
}
$this->data[$id] = array('id' => $id, 'key' => $key, 'name' => $name);
}
示例4: handleException
protected function handleException(Throwable $e)
{
if (response()->getCode() == 200) {
response()->code(404);
}
$code = $e->getCode() ? $e->getCode() : response()->getCode();
$message = $e->getMessage();
if (class_exists(DeriveAssets::class)) {
Reflect::create(DeriveAssets::class)->register();
}
$handled = false;
$codes = [$code, 'default'];
foreach ($codes as $file) {
try {
$response = view('Pckg\\Framework:error/' . $file, ['message' => $message, 'code' => $code, 'exception' => $e])->autoparse();
if ($response) {
$handled = true;
break;
}
} catch (Throwable $e) {
dd(exception($e));
}
}
if ($handled) {
echo $response;
} else {
echo $code . ' : ' . $message;
}
exit;
}
示例5: JsonToArray
public function JsonToArray($json)
{
if (isJson($json)) {
$array = json_decode($json, true);
return $array;
} else {
throw exception("Invalid Json Array");
}
}
示例6: __construct
/**
* @param array $options
*/
public function __construct($options = array())
{
if (!extension_loaded('memcache')) {
exception('_nofund_' . ':memcache');
}
$options = array_merge(array('host' => C('cache:memcache:host') ?: '127.0.0.1', 'port' => C('cache:memcache:port') ?: 11211, 'timeout' => C('cache:memcache:timeout') ?: false, 'persistent' => false), $options);
$this->options = $options;
$this->options['expire'] = isset($options['expire']) ? $options['expire'] : C('cache:expire');
$this->options['prefix'] = isset($options['prefix']) ? $options['prefix'] : C('cache:prefix');
$func = $options['persistent'] ? 'pconnect' : 'connect';
$this->handler = new \Memcache();
$options['timeout'] === false ? $this->handler->{$func}($options['host'], $options['port']) : $this->handler->{$func}($options['host'], $options['port'], $options['timeout']);
}
示例7: execute
public function execute(callable $next)
{
try {
/**
* First argument is always 'console'.
* Second argument is app name or command.
* If it's command, we leave things as they are.
* Id it's app, we unset it.
*/
$argv = $_SERVER['argv'];
/**
* Remove application name.
*/
if (isset($argv[1]) && !strpos($argv[1], ':')) {
unset($argv[1]);
}
/**
* Remove platform name.
*/
if (isset($argv[2]) && !strpos($argv[2], ':') && false === strpos($argv[2], '-')) {
unset($argv[2]);
}
/**
* Get Symfony Console Application, find available commands and run app.
*/
$application = context()->get(SymfonyConsole::class);
try {
/**
* Apply global middlewares.
*/
if ($middlewares = $this->response->getMiddlewares()) {
chain($middlewares, 'execute');
}
$application->run(new ArgvInput(array_values($argv)));
/**
* Apply global afterwares/decorators.
*/
if ($afterwares = $this->response->getAfterwares()) {
chain($afterwares, 'execute', [$this->response]);
}
} catch (Throwable $e) {
die("EXCEPTION: " . exception($e));
}
/**
* This is here just for better readability. =)
*/
echo "\n";
} catch (Throwable $e) {
}
return $next();
}
示例8: init
/**
* 初始化
* @param $config
*/
public function init($type = '', $options = array())
{
if (empty($type)) {
$type = C('cache_type');
}
$type = strtolower(trim($type));
$class = 'System\\Library\\Cache\\cache' . ucwords($type);
if (class_exists($class)) {
$this->cache = new $class($options);
} else {
exception('CACHE_TYPE Error:' . $type);
}
return $this->cache;
}
示例9: getAvailableRelations
public function getAvailableRelations()
{
return $this->table->relations->each(function (Relation $relation) {
$entity = $relation->showTable->createEntity();
$options = $relation->onField && $relation->dynamic_relation_type_id == 1 ? $entity->all()->each(function ($record) use($relation, $entity) {
try {
$eval = eval(' return ' . $relation->value . '; ');
} catch (Throwable $e) {
$eval = exception($e);
}
return ['key' => $record->id, 'value' => $eval];
}, true) : [];
return ['id' => $relation->id, 'field' => $relation->id, 'table' => $relation->showTable->table, 'fields' => $this->makeFields($relation->showTable->fields), 'type' => $relation->dynamic_relation_type_id, 'options' => ['options' => $options]];
});
}
示例10: routeToCm
/**
* 控制器实现
*/
public static function routeToCm()
{
//require_once(APP_PATH.'/'.ucfirst(self::$routeUrl['module']).'/Controller/abstractController.php');
//require_once(APP_PATH.'/'.ucfirst(self::$routeUrl['module']).'/Controller/'.self::$routeUrl['controller'].'Controller.php');
//Admin\Controller\Index;
$controller = "\\" . ucfirst(self::$routeUrl['module']) . "\\Controller\\" . self::$routeUrl['controller'] . 'Controller';
$controller = new $controller();
$action = self::$routeUrl['action'] . 'Action';
try {
$ca = new \ReflectionMethod($controller, $action);
$ca->invoke(new $controller(), isset($params) ? $params : null);
} catch (\Exception $e) {
exception('控制器方法' . $action . '不存在');
}
}
示例11: action
function action()
{
// This needs form validation in a bad way.
$site = owa_coreAPI::entityFactory('base.site');
if (!$this->getParam('siteId')) {
throw exception('No siteId passed on request');
}
$site->load($site->generateId($this->getParam('siteId')));
$site->set('name', $this->getParam('name'));
$site->set('domain', $this->getParam('domain'));
$site->set('description', $this->getParam('description'));
$site->save();
//$data['view_method'] = 'redirect';
//$data['do'] = 'base.sites';
$this->setRedirectAction('base.sites');
$this->set('status_code', 3201);
}
示例12: __construct
function __construct($l = NULL)
{
$lang = api_config::getInstance()->lang;
if (!$l) {
$currentLang = $lang['default'];
} else {
if (in_array($l, $lang['languages'])) {
$currentlang = $l;
} else {
// No language what to do?
throw exception(new Exception("Language {$l} missing"));
}
}
$langFile = PROJECT_DIR . "config/locale/" . $currentLang . ".yml";
$yaml = file_get_contents($langFile);
$langYaml = sfYaml::load($yaml);
$langArray = $langYaml[$currentLang];
$this->content = $langArray;
}
示例13: fetch
public function fetch($templateFile = '', $content = '', $prefix = '')
{
if (empty($content)) {
$templateFile = $this->parseTemplate($templateFile);
if (!is_file($templateFile)) {
exception("模板文件" . $templateFile . "不存在");
}
}
ob_start();
ob_implicit_flush(0);
if ('php' == strtolower($this->config['tmpl_engine_type'])) {
extract($this->tVar, EXTR_OVERWRITE);
empty($content) ? include $templateFile : eval('?>' . $content);
} else {
$params = array('var' => $this->tVar, 'file' => $templateFile, 'content' => $content, 'prefix' => $prefix);
$this->ParseTemplateBehavior($params);
}
$content = ob_get_clean();
$this->ContentReplaceBehavior($content);
return $content;
}
示例14: handle
/**
* We
*/
public function handle()
{
$this->app = $this->getApp();
if (!$this->app) {
throw new Exception('App name is required in migrator');
}
context()->bind(InstallMigrator::class, $this);
$requestedMigrations = $this->getRequestedMigrations();
$installedMigrations = (array) $this->getInstalledMigrations();
$installed = 0;
$updated = 0;
foreach ($requestedMigrations as $requestedMigration) {
/**
* @T00D00
* Implement beforeFirstUp(), beforeUp(), afterUp(), afterFirstUp(), isFirstUp()
*/
try {
$migration = new $requestedMigration();
$migration->up();
if (!in_array($requestedMigration, $installedMigrations)) {
$migration->afterFirstUp();
}
$this->output($migration->getRepository() . ' : ' . $requestedMigration);
$this->output();
} catch (Throwable $e) {
dd(exception($e));
}
if (in_array($requestedMigration, $installedMigrations)) {
$updated++;
} else {
$installedMigrations[] = $requestedMigration;
$installed++;
}
}
$this->output('Updated: ' . $updated);
$this->output('Installed: ' . $installed);
$this->output('Total: ' . count($installedMigrations));
$this->putInstalledMigrations($installedMigrations);
}
示例15: internal
public function internal($url = null)
{
try {
if (!$url) {
$url = $_SERVER['REQUEST_URI'];
}
message('Internal redirect to ' . $url);
/**
* Set GET method.
*/
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = $url;
$_POST = [];
/**
* Replace prefix in url because environment was already set.
*/
$url = env()->replaceUrlPrefix($url);
/**
* Set request url.
*/
request()->setUrl($url);
/**
* Make request internal so we increase counter.
*/
request()->setInternal();
/**
* Find match.
*/
request()->init();
/**
* Run actions.
*/
request()->run();
/**
* Output.
*/
response()->run();
exit;
} catch (Throwable $e) {
if (prod()) {
die(exception($e));
die("Unknown internal error");
}
die(exception($e));
}
exit;
}