本文整理汇总了PHP中RuntimeException函数的典型用法代码示例。如果您正苦于以下问题:PHP RuntimeException函数的具体用法?PHP RuntimeException怎么用?PHP RuntimeException使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RuntimeException函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: verifyConsole
protected function verifyConsole()
{
$request = $this->getRequest();
if (!$request instanceof ConsoleRequest) {
throw RuntimeException(sprintf('%s can only be run via the Console', __METHOD__));
}
}
示例2: getRestaurantUri
/** @inheritdoc */
public function getRestaurantUri($restaurantId)
{
$config = $this->configRestaurant($restaurantId);
if (isset($config['uri'])) {
return $config['uri'];
}
throw \RuntimeException('Restaurant has no URI configured');
}
示例3: createTwigFileSystemLoader
public function createTwigFileSystemLoader()
{
$dir = $this->getTemplateDir();
if (!file_exists($dir)) {
throw RuntimeException("Directory {$dir} for TemplateView does not exist.");
}
return new Twig_Loader_Filesystem($dir);
}
示例4: charger
public static function charger()
{
if (null !== self::$_instance) {
throw new RuntimeException(sprintf('%s is already started', __CLASS__));
}
self::$_instance = new self();
if (!spl_autoload_register(array(self::$_instance, '_autoload'), false)) {
throw RuntimeException(sprintf('%s : Could not start the autoload', __CLASS__));
}
}
示例5: getEventName
public function getEventName()
{
if (empty($this->eventName)) {
if (!static::EVENT_NAME) {
throw \RuntimeException('Your must have set one event name');
}
return static::EVENT_NAME;
}
return $this->eventName;
}
示例6: getService
public function getService($name)
{
if ($name === 'solve_media') {
return $this->app->SolveMediaService;
} else {
if ($name === 'recaptcha') {
return $this->app->RecaptchaService;
}
}
throw RuntimeException();
}
示例7: _replace
/**
* Does file replacements.
*
* @param array $matches
*/
protected function _replace($matches)
{
$required = empty($matches[2]) ? $matches[4] : $matches[2];
$filename = $this->_Scanner->find($required);
if (!$filename) {
throw RuntimeException('Could not find dependency');
}
if (empty($this->_loaded[$filename])) {
return $this->input($filename, file_get_contents($filename));
}
return '';
}
示例8: changeAuthenticatedUserAvatar
/**
* Create new avatar image for current authenticated user
* @param string $sUserAvatarFilePath
* @throws \InvalidArgumentException
* @throws \RuntimeException
* @throws \DomainException
* @throws \LogicException
* @return \BoilerAppUser\Service\UserAccountService
*/
public function changeAuthenticatedUserAvatar($sUserAvatarFilePath)
{
if (!is_string($sUserAvatarFilePath)) {
throw new \InvalidArgumentException('User avatar path expects string, "' . gettype($sUserAvatarFilePath) . '" given');
}
if (!is_readable($sUserAvatarFilePath)) {
throw new \InvalidArgumentException('User avatar path "' . $sUserAvatarFilePath . '" is not a readable file path');
}
if (!($aImagesInfos = @getimagesize($sUserAvatarFilePath)) || empty($aImagesInfos[2])) {
\RuntimeException('An error occurred while retrieving user avatar "' . $sUserAvatarFilePath . '" infos');
}
switch ($aImagesInfos[2]) {
case IMAGETYPE_JPEG:
if (!($oImage = imagecreatefromjpeg($sUserAvatarFilePath))) {
throw new \RuntimeException('An error occurred during creating image from "jpeg" user avatar "' . $sUserAvatarFilePath . '"');
}
break;
case IMAGETYPE_GIF:
if (!($oImage = imagecreatefromgif($sUserAvatarFilePath))) {
throw new \RuntimeException('An error occurred during creating image from "gif" user avatar "' . $sUserAvatarFilePath . '"');
}
break;
case IMAGETYPE_PNG:
if (!($oImage = imagecreatefrompng($sUserAvatarFilePath))) {
throw new \RuntimeException('An error occurred during creating image from "png" user avatar "' . $sUserAvatarFilePath . '"');
}
break;
default:
throw new \DomainException('File type "' . $aImagesInfos[2] . '" is not supported for avatar');
}
//Crop image
if (!($oNewImage = imagecreatetruecolor(128, 128))) {
throw new \RuntimeException('An error occurred during creating new image for croping user avatar');
}
if (!imagecopyresampled($oNewImage, $oImage, 0, 0, 0, 0, 128, 128, imagesx($oImage), imagesy($oImage))) {
throw new \RuntimeException('An error occurred during croping user avatar');
}
$aConfiguration = $this->getServiceLocator()->get('Config');
if (empty($aConfiguration['paths']['avatarsPath'])) {
throw new \LogicException('Avatars directory path is undefined');
}
if (!is_string($aConfiguration['paths']['avatarsPath'])) {
throw new \LogicException('Avatars directory path expects string, "' . gettype($aConfiguration['paths']['avatarsPath']) . '" given');
}
if (!is_dir($aConfiguration['paths']['avatarsPath'])) {
throw new \LogicException('Avatars directory path expects string, "' . $aConfiguration['paths']['avatarsPath'] . '" is not a valid directory');
}
//Save avatar
if (!imagepng($oNewImage, $aConfiguration['paths']['avatarsPath'] . DIRECTORY_SEPARATOR . $this->getServiceLocator()->get('AccessControlService')->getAuthenticatedAuthAccess()->getAuthAccessUser()->getUserId() . '-avatar.png')) {
throw new \RuntimeException('An error occurred during saving user avatar');
}
return $this;
}
示例9: ensureWritableDir
public function ensureWritableDir($path, $mode = 0777)
{
$dir = $this->getPath($path);
if (!is_dir($dir)) {
if (!mkdir($dir, $mode, true)) {
throw \RuntimeException('Cant Create ' . $dir);
}
}
if (!is_writable($dir)) {
if (!chmod($dir, $mode)) {
throw \RuntimeException('Cant Change Permission ' . $dir);
}
}
return true;
}
示例10: actionPerformed
public function actionPerformed($action)
{
switch ($action) {
case self::do_use:
$this->state->doUse($this);
break;
case self::do_alarm:
$this->state->doAlarm($this);
break;
case self::do_phone:
$this->state->doPhone($this);
break;
default:
throw RuntimeException(__LINE__ . ' ' . __METHOD__);
break;
}
}
示例11: ensure_directory
/**
* ensures a directory exist, by creating it if it does no & it's possible to
*
* @param string $dir directory
*/
function ensure_directory($dir)
{
if (file_exists($dir)) {
if (!is_dir($dir)) {
throw new InvalidArgumentException($dir);
}
} else {
$dir = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $dir));
$cDir = '';
//complete dir
foreach ($dir as $d) {
$cDir .= $d . '/';
if (!file_exists($cDir) && !@mkdir($cDir)) {
throw RuntimeException("can't create {$cDir}");
}
}
}
}
示例12: payCallBackAction
public function payCallBackAction(Request $request, $name)
{
$controller = $this;
$status = $this->doPayNotify($request, $name, function ($success, $order) use(&$controller) {
if (!$success) {
return;
}
if ($order['targetType'] != 'course') {
throw \RuntimeException('非课程订单,加入课程失败。');
}
$info = array('orderId' => $order['id'], 'remark' => empty($order['data']['note']) ? '' : $order['data']['note']);
if (!$controller->getCourseService()->isCourseStudent($order['targetId'], $order['userId'])) {
$controller->getCourseService()->becomeStudent($order['targetId'], $order['userId'], $info);
$controller->getLogService()->info('order', 'callback_success', "paycalknotify action");
}
return;
});
$callback = "<script type='text/javascript'>window.location='objc://alipayCallback?" . $status . "';</script>";
return new Response($callback);
}
示例13: init
/**
* Initialize image information
* @throws RuntimeException
*/
public function init($file)
{
if (!file_exists($file)) {
throw \InvalidArgumentException("source image does not exists");
}
$this->file = $file;
if (!($info = getimagesize($this->file))) {
throw new \RuntimeException("source image does not exists : " . $this->file);
}
$this->width = $info[0];
$this->height = $info[1];
$mime = $info['mime'];
$this->type = str_replace('image/', '', $mime);
$func = 'imagecreatefrom' . $this->type;
if (!function_exists($func)) {
throw \RuntimeException("Format not supported");
}
$this->file = $func($this->file);
return $this;
}
示例14: usdMxn
/**
* Retrieves the exchange rate of the USD specified in MXN as calculated
* from "http://dof.gob.mx/indicadores.php".
*
* @throws RuntimeException When client could not connect to the webserver
* at dof.gob.mx and thus USD value could not be retrieved.
*
* @return float
*/
public function usdMxn()
{
$query = http_build_query(['cod_tipo_indicador' => '158', 'dfecha' => Carbon::now()->subMonth()->format('d/m/Y'), 'hfecha' => Carbon::now()->format('d/m/Y')]);
$url = 'http://dof.gob.mx/indicadores_detalle.php?' . $query;
$webContent = file_get_contents($url);
if (!$webContent) {
throw RuntimeException("Couldn't connect to dof.gob.mx server!");
}
$dom = new \DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($webContent);
$items = $dom->getElementsByTagName('tr');
$entries = [];
foreach ($items as $tag) {
if (!$tag->hasAttribute('class')) {
continue;
}
if ($tag->getAttribute('class') != 'Celda 1') {
continue;
}
$entries[] = $this->helpers->parseNodes($tag->childNodes);
}
return $this->helpers->mostRecentEntry($entries)['rate'];
}
示例15: parse
public function parse()
{
throw RuntimeException('It need use parse() function in sub class.');
}