Example #1
0
 /**
  * Render the document
  *
  * @param   boolean  $cache   If true, cache the output
  * @param   array    $params  Associative array of attributes
  *
  * @return  string   The rendered data
  *
  * @since   11.1
  */
 public function render($cache = false, $params = array())
 {
     // If no error object is set return null
     if (!isset($this->_error)) {
         return;
     }
     //Set the status header
     JResponse::setHeader('status', $this->_error->getCode() . ' ' . str_replace("\n", ' ', $this->_error->getMessage()));
     $file = 'error.php';
     // check template
     $directory = isset($params['directory']) ? $params['directory'] : 'templates';
     $template = isset($params['template']) ? JFilterInput::getInstance()->clean($params['template'], 'cmd') : 'system';
     if (!file_exists($directory . '/' . $template . '/' . $file)) {
         $template = 'system';
     }
     //set variables
     $this->baseurl = JURI::base(true);
     $this->template = $template;
     $this->debug = isset($params['debug']) ? $params['debug'] : false;
     $this->error = $this->_error;
     // load
     $data = $this->_loadTemplate($directory . '/' . $template, $file);
     parent::render();
     return $data;
 }
 /**
  * Render the document
  *
  * @param   boolean  $cache   If true, cache the output
  * @param   array    $params  Associative array of attributes
  *
  * @return  string   The rendered data
  *
  * @since   11.1
  */
 public function render($cache = false, $params = array())
 {
     // If no error object is set return null
     if (isset($this->_error)) {
         $code = $this->_error->getCode();
         if (!isset(JHttpResponse::$status_messages[$code])) {
             $code = '500';
         }
         if (ini_get('display_errors')) {
             $message = $this->_error->getMessage();
         } else {
             $message = JHttpResponse::$status_messages[$code];
         }
         // Set the status header
         JFactory::getApplication()->setHeader('status', $code . ' ' . str_replace("\n", ' ', $message));
         $file = 'error.php';
         // Check template
         $directory = isset($params['directory']) ? $params['directory'] : 'templates';
         $template = isset($params['template']) ? JFilterInput::getInstance()->clean($params['template'], 'cmd') : 'system';
         if (!file_exists($directory . '/' . $template . '/' . $file)) {
             $template = 'system';
         }
         // Set variables
         $this->baseurl = JUri::base(true);
         $this->template = $template;
         $this->error = $this->_error;
         $this->debug = isset($params['debug']) ? $params['debug'] : false;
         $this->code = isset($params['code']) ? $params['code'] : $code;
         $this->message = isset($params['message']) ? $params['message'] : $message;
         // Load
         $data = $this->_loadTemplate($directory . '/' . $template, $file);
         parent::render();
         return $data;
     }
 }
 /**
  * Axis must be provided for new variant group
  *
  * @param object     $variantGroup
  * @param Constraint $constraint
  */
 public function validate($variantGroup, Constraint $constraint)
 {
     /** @var GroupInterface */
     if ($variantGroup instanceof GroupInterface) {
         $isNew = $variantGroup->getId() === null;
         $isVariantGroup = $variantGroup->getType()->isVariant();
         $hasAxis = count($variantGroup->getAxisAttributes()) > 0;
         if ($isNew && $isVariantGroup && !$hasAxis) {
             $this->context->addViolation($constraint->expectedAxisMessage, array('%variant group%' => $variantGroup->getCode()));
         } elseif (!$isVariantGroup && $hasAxis) {
             $this->context->addViolation($constraint->unexpectedAxisMessage, array('%group%' => $variantGroup->getCode()));
         }
     }
 }
 /**
  * @param  object                                                $attribute
  * @param  null                                                  $format
  * @param  array                                                 $context
  * @return array|\Symfony\Component\Serializer\Normalizer\scalar
  */
 public function normalize($attribute, $format = null, array $context = [])
 {
     /**@var Attribute $attribute * */
     $normalizedAttribute = ['code' => null, 'type' => null, 'required' => null, 'labels' => null, 'parameters' => null];
     $availableLocales = [];
     $attributeAvailableLocales = $attribute->getAvailableLocales();
     if (!is_null($attributeAvailableLocales)) {
         foreach ($attribute->getAvailableLocales() as $availableLocale) {
             $availableLocales [] = $availableLocale;
         }
     }
     $allowed_extensions = [];
     foreach ($attribute->getAllowedExtensions() as $allowed_extension) {
         $allowed_extensions [] = $allowed_extension;
     }
     $normalizedAttribute['required'] = $attribute->isRequired();
     $normalizedAttribute['type'] = $attribute->getAttributeType();
     $normalizedAttribute['code'] = $attribute->getCode();
     $normalizedAttribute['parameters'] = ['scope' => $attribute->isScopable(), 'localizable' => $attribute->isLocalizable(), 'available_locales' => $availableLocales, 'max_file_size' => $attribute->getMaxFileSize(), 'allowed_extensions' => $allowed_extensions];
     if ($attribute->isLocalizable()) {
         foreach ($attribute->getTranslations() as $trans) {
             $normalizedAttribute['labels'][$trans->getLocale()] = $trans->getLabel();
         }
     } else {
         $normalizedAttribute['labels'][LANGUAGE_NONE] = $attribute->getLabel();
     }
     return $normalizedAttribute;
 }
 /**
  * Render the document
  *
  * @param   boolean $cache  If true, cache the output
  * @param   array   $params Associative array of attributes
  *
  * @return  string   The rendered data
  *
  * @since   11.1
  */
 public function render($cache = false, $params = array())
 {
     // If no error object is set return null
     if (!isset($this->_error)) {
         return;
     }
     // Set the status header
     \JFactory::getApplication()->setHeader('status', $this->_error->getCode() . ' ' . str_replace("\n", ' ', $this->_error->getMessage()));
     $file = 'error.php';
     // Check template
     $directory = isset($params['directory']) ? $params['directory'] : 'templates';
     $template = isset($params['template']) ? \JFilterInput::getInstance()->clean($params['template'], 'cmd') : 'system';
     if (!file_exists($directory . '/' . $template . '/' . $file)) {
         $template = 'system';
     }
     // Set variables
     $this->baseurl = \JUri::base(true);
     $this->template = $template;
     $this->debug = isset($params['debug']) ? $params['debug'] : false;
     $this->error = $this->_error;
     $params['params'] = \JFactory::getApplication()->getTemplate(true)->params;
     // Load
     $params['file'] = 'error.php';
     $this->parse($params);
     $data = $this->_renderTemplate();
     parent::render();
     return $data;
 }
Example #6
0
 /**
  * Обвертка для функции _query
  *
  * @param  string  $queryText поисковый запрос (в оригинальном виде)
  * @param  integer $store     ИД текущего магазина
  * @param  object  $index     индекс по которому нужно провести поиск
  *
  * @return array масив ИД елементов, где ИД - ключ, релевантность значение
  */
 public function query($queryText, $store, $index)
 {
     $indexCode = $index->getCode();
     $primaryKey = $index->getPrimaryKey();
     $attributes = $index->getAttributes();
     if ($store) {
         $store = array($store);
     }
     return $this->_query($queryText, $store, $indexCode, $primaryKey, $attributes);
 }
Example #7
0
 /**
  * Render the error page based on an exception.
  *
  * @param   object  $error  An Exception or Throwable (PHP 7+) object for which to render the error page.
  *
  * @return  void
  *
  * @since   3.0
  */
 public static function render($error)
 {
     $expectedClass = PHP_MAJOR_VERSION >= 7 ? 'Throwable' : 'Exception';
     $isException = $error instanceof $expectedClass;
     // In PHP 5, the $error object should be an instance of Exception; PHP 7 should be a Throwable implementation
     if ($isException) {
         try {
             $app = JFactory::getApplication();
             $document = JDocument::getInstance('error');
             $code = $error->getCode();
             if (!isset(JHttpResponse::$status_messages[$code])) {
                 $code = '500';
             }
             if (ini_get('display_errors')) {
                 $message = $error->getMessage();
             } else {
                 $message = JHttpResponse::$status_messages[$code];
             }
             if (!$document || PHP_SAPI == 'cli') {
                 // We're probably in an CLI environment
                 jexit($message);
             }
             // Get the current template from the application
             $template = $app->getTemplate();
             // Push the error object into the document
             $document->setError($error);
             if (ob_get_contents()) {
                 ob_end_clean();
             }
             $document->setTitle(JText::_('Error') . ': ' . $code);
             $data = $document->render(false, array('template' => $template, 'directory' => JPATH_THEMES, 'debug' => JFactory::getConfig()->get('debug')));
             // Do not allow cache
             $app->allowCache(false);
             // If nothing was rendered, just use the message from the Exception
             if (empty($data)) {
                 $data = $message;
             }
             $app->setBody($data);
             echo $app->toString();
             return;
         } catch (Exception $e) {
             // Pass the error down
         }
     }
     // This isn't an Exception, we can't handle it.
     if (!headers_sent()) {
         header('HTTP/1.1 500 Internal Server Error');
     }
     $message = 'Error displaying the error page';
     if ($isException) {
         $message .= ': ' . $e->getMessage() . ': ' . $message;
     }
     echo $message;
     jexit(1);
 }
 /**
  * constructor
  *
  */
 public function __construct()
 {
     $console_config = $this->getConfigArray();
     $configArray = array();
     // cli view argument definition
     $configArray['view'] = array('short' => 'v', 'min' => 1, 'max' => 1, 'desc' => 'Set the view to execute.');
     $console_config = array_merge($configArray, $console_config);
     $this->args =& Console_Getargs::factory($console_config);
     if (PEAR::isError($this->args)) {
         $mes = '';
         if ($this->args->getCode() === CONSOLE_GETARGS_ERROR_USER) {
             $mes = Console_Getargs::getHelp($console_config, null, $this->args->getMessage()) . "\n\n";
         } else {
             if ($this->args->getCode() === CONSOLE_GETARGS_HELP) {
                 $mes = Console_Getargs::getHelp($console_config) . "\n\n";
             }
         }
         $this->printError($mes);
     }
 }
 /**
  * @param  object $admin
  * @return false | int
  */
 public function generate($admin, $bundle)
 {
     $admin_name = $this->getAdminNameFromAdminCode($admin->getCode());
     $file_path = sprintf('%s/Tests/%sAdminTest.php', $bundle->getPath(), $admin_name);
     dump($file_path);
     $form_builder = $admin->getFormBuilder();
     // var_dump($builder->get('disponibility')->getAttributes()['data_collector/passed_options']['choices']);
     //var_dump($form_builder->get('vehicle_model')->getForm()->getConfig()->getOption('callback'));
     // var_dump($admin->getFormFieldDescription('disponibility'));
     $namespace = $this->getNamespace($admin);
     return $this->renderFile('AdminTests.php.twig', $file_path, array('admin' => $admin, 'form_builder' => $form_builder, 'admin_name' => $admin_name, 'namespace' => $namespace));
 }
Example #10
0
 /**
 * 常量(启用命名空间后的常量名) 	说明
  	YAF_VERSION(Yaf\VERSION)  Yaf框架的三位版本信息
 		YAF_ENVIRON(Yaf\ENVIRON   Yaf的环境常量, 指明了要读取的配置的节, 默认的是product
    YAF_ERR_STARTUP_FAILED(Yaf\ERR\STARTUP_FAILED)  Yaf的错误代码常量, 表示启动失败, 值为512
    YAF_ERR_ROUTE_FAILED(Yaf\ERR\ROUTE_FAILED)  Yaf的错误代码常量, 表示路由失败, 值为513
    YAF_ERR_DISPATCH_FAILED(Yaf\ERR\DISPATCH_FAILED)  Yaf的错误代码常量, 表示分发失败, 值为514
    YAF_ERR_NOTFOUND_MODULE(Yaf\ERR\NOTFOUD\MODULE)   Yaf的错误代码常量, 表示找不到指定的模块, 值为515
    YAF_ERR_NOTFOUND_CONTROLLER(Yaf\ERR\NOTFOUD\CONTROLLER)   Yaf的错误代码常量, 表示找不到指定的Controller, 值为516
    YAF_ERR_NOTFOUND_ACTION(Yaf\ERR\NOTFOUD\ACTION)   Yaf的错误代码常量, 表示找不到指定的Action, 值为517
    YAF_ERR_NOTFOUND_VIEW(Yaf\ERR\NOTFOUD\VIEW)   Yaf的错误代码常量, 表示找不到指定的视图文件, 值为518
    YAF_ERR_CALL_FAILED(Yaf\ERR\CALL_FAILED)  Yaf的错误代码常量, 表示调用失败, 值为519
    YAF_ERR_AUTOLOAD_FAILED(Yaf\ERR\AUTOLOAD_FAILED)  Yaf的错误代码常量, 表示自动加载类失败, 值为520
    YAF_ERR_TYPE_ERROR(Yaf\ERR\TYPE_ERROR)  Yaf的错误代码常量, 表示关键逻辑的参数错误, 值为521
    $this->getRequest ()->getModuleName ();
    $this->getRequest ()->getControllerName ();
    $this->getRequest ()->getActionName ();
    $exception->getCode ();
    $exception->getMessage ();
 * @param object $exception
 */
 public function errorAction($exception)
 {
     error_reporting(E_ERROR);
     //定义错误信息
     switch ($exception->getCode()) {
         case YAF_ERR_STARTUP_FAILED:
             $message = Lang::goLang('YAF_ERR_STARTUP_FAILED');
             //512
             break;
         case YAF_ERR_ROUTE_FAILED:
             $message = Lang::goLang('YAF_ERR_ROUTE_FAILED');
             //513
             break;
         case YAF_ERR_DISPATCH_FAILED:
             $message = Lang::goLang('YAF_ERR_DISPATCH_FAILED');
             //514
             break;
         case YAF_ERR_NOTFOUND_MODULE:
             $message = Lang::goLang('YAF_ERR_NOTFOUND_MODULE');
             //515
             break;
         case YAF_ERR_NOTFOUND_CONTROLLER:
             $message = Lang::goLang('YAF_ERR_NOTFOUND_CONTROLLER');
             //516
             break;
         case YAF_ERR_NOTFOUND_ACTION:
             $message = Lang::goLang('YAF_ERR_NOTFOUND_ACTION');
             //517
             break;
         case YAF_ERR_NOTFOUND_VIEW:
             $message = Lang::goLang('YAF_ERR_NOTFOUND_VIEW');
             //518
             break;
         case YAF_ERR_CALL_FAILED:
             $message = Lang::goLang('YAF_ERR_CALL_FAILED');
             //519
             break;
         case YAF_ERR_AUTOLOAD_FAILED:
             $message = Lang::goLang('YAF_ERR_AUTOLOAD_FAILED');
             //520
             break;
         case YAF_ERR_TYPE_ERROR:
             $message = Lang::goLang('YAF_ERR_TYPE_ERROR');
             //521
             break;
         default:
             $message = $exception;
             break;
     }
     // var_dump($message);die;
     $this->getView()->assign("message", '找不到该页面404');
     $this->getView()->assign("url", BASEURL);
 }
 /**
  * @param  object                                                $group
  * @param  null                                                  $format
  * @param  array                                                 $context
  * @return array|\Symfony\Component\Serializer\Normalizer\scalar
  */
 public function normalize($group, $format = null, array $context = [])
 {
     /**@var Group $group * */
     $normalizedGroup = ['code' => $group->getCode(), 'type' => $group->getType()->getCode()];
     foreach ($group->getTranslations() as $trans) {
         $normalizedGroup['labels'][$trans->getLocale()] = $trans->getLabel();
     }
     foreach ($group->getAttributes() as $attr) {
         $normalizedGroup['attributes'][] = $attr->getCode();
     }
     return $normalizedGroup;
 }
Example #12
0
 /**
  * Handle an error
  *
  * @param   object  $error
  * @return  void
  */
 public static function handleError(&$error)
 {
     // Make sure the error is a 403 and we are in the frontend.
     if ($error->getCode() == 403 and App::isSite()) {
         // Redirect to the home page
         App::redirect('index.php', Lang::txt('PLG_SYSTEM_LOGOUT_REDIRECT'), null, true, false);
     } else {
         // Render the error page.
         $renderer = new \Hubzero\Error\Renderer\Page(App::get('document'), App::get('template')->template, App::get('config')->get('debug'));
         $renderer->render($error);
     }
 }
Example #13
0
 /**
  * Gets Information (message, code, file, line, trace) of an Exception.
  *
  * @param object $oE Exception object.
  * @return string
  */
 public static function getInfoExcept($oE)
 {
     $sDebug = $oE->getMessage();
     $sDebug .= '<br />';
     $sDebug = $oE->getCode();
     $sDebug .= '<br />';
     $sDebug = $oE->getFile();
     $sDebug .= '<br />';
     $sDebug = $oE->getLine();
     $sDebug .= '<br />';
     $sDebug .= $oE->getTraceAsString();
     return $sDebug;
 }
Example #14
0
 /**
  * Error...
  *
  * @param object $e error object
  *
  * @return null
  */
 function Nexista_builderError($e)
 {
     if ($e->getCode() == NX_ERROR_FATAL || $e->getCode() == NX_ERROR_WARNING) {
         $use_xslt_cache = 'yes';
         if ($use_xslt_cache != 'yes' || !class_exists('xsltCache')) {
             $exceptionXsl = new XsltProcessor();
         } else {
             $exceptionXsl = new xsltCache();
         }
         $xsl = new DomDocument();
         $my_xsl_file = NX_PATH_BASE . 'extensions/dev_buffer/s/xsl/exception.xsl';
         if (file_exists($my_xsl_file)) {
             $xsl->load($my_xsl_file);
             $exceptionXsl->importStyleSheet($xsl);
             $xml = new DomDocument();
             $xml->loadXML($e->outputXml());
             $exceptionXsl->setParameter('', 'link_prefix', dirname($_SERVER['SCRIPT_NAME']) . '/index.php?nid=');
             $result = $exceptionXsl->transformToXML($xml);
             echo $result;
         }
     }
 }
Example #15
0
 /**
  *  Метод для записи логов
  *  @param object $e Объект класса Exception
  *  @return bool Вернет истину если файл запишется
  */
 public function writeLog($e)
 {
     $datetime = date('d/m/y H:i:s');
     $msg = date('d/m/y H:i:s') . '||';
     $msg .= 'Код: ' . $e->getCode() . '||';
     $msg .= 'Сообщение: ' . $e->getMessage() . '||';
     $msg .= 'Линия: ' . $e->getLine() . '||';
     $msg .= 'Файл: ' . $e->getFile() . "\n";
     if (!file_put_contents(Config::LOGS, $msg, FILE_APPEND | LOCK_EX)) {
         return false;
     } else {
         return true;
     }
 }
 /**
  * Connect to database by using the given DSN string
  *
  * @access private
  * @param  string DSN string
  * @return mixed  Object on error, otherwise bool
  */
 function _connect(&$dsn)
 {
     if (is_string($dsn) || is_array($dsn)) {
         $this->db =& DB::connect($dsn, $this->options['db_options']);
     } elseif (is_subclass_of($dsn, "db_common")) {
         $this->db =& $dsn;
     } else {
         return PEAR::raiseError("Invalid dsn or db object given");
     }
     if (DB::isError($this->db) || PEAR::isError($this->db)) {
         return PEAR::raiseError($this->db->getMessage(), $this->db->getCode());
     } else {
         return true;
     }
 }
 /**
  * Axis must be provided for new variant group
  *
  * @param object     $variantGroup
  * @param Constraint $constraint
  */
 public function validate($variantGroup, Constraint $constraint)
 {
     /* @var GroupInterface */
     if ($variantGroup instanceof GroupInterface) {
         $isNew = null === $variantGroup->getId();
         $isVariantGroup = $variantGroup->getType()->isVariant();
         $hasAxis = count($variantGroup->getAxisAttributes()) > 0;
         if ($isNew && $isVariantGroup && !$hasAxis) {
             $this->addExpectedAxisViolation($constraint, $variantGroup->getCode());
         } elseif ($isVariantGroup && $hasAxis) {
             $this->validateAttributeAxis($constraint, $variantGroup);
         } elseif (!$isVariantGroup && $hasAxis) {
             $this->addUnexpectedAxisViolation($constraint, $variantGroup->getCode());
         }
     }
 }
 /**
  * Connect to database by using the given DSN string
  *
  * @access private
  * @param  string DSN string
  * @return mixed  Object on error, otherwise bool
  */
 function _connect(&$dsn)
 {
     $this->log('Auth_Container_DBLite::_connect() called.', AUTH_LOG_DEBUG);
     if (is_string($dsn) || is_array($dsn)) {
         $this->db =& DB::connect($dsn, $this->options['db_options']);
     } elseif (is_subclass_of($dsn, "db_common")) {
         $this->db =& $dsn;
     } else {
         return PEAR::raiseError("Invalid dsn or db object given");
     }
     if (DB::isError($this->db) || PEAR::isError($this->db)) {
         return PEAR::raiseError($this->db->getMessage(), $this->db->getCode());
     } else {
         return true;
     }
 }
Example #19
0
 /**
  * Init MDB2 container
  *
  * @access public
  * @return void
  * @throws HTTP_FloodControl_Exception if it is impossible to establish database connection.
  */
 public function set()
 {
     $dsn = $this->_options['dsn'];
     if (is_string($dsn) || is_array($dsn)) {
         $this->_db = MDB2::connect($dsn);
     } else {
         if (is_object($dsn) && is_a($dsn, 'MDB2_Driver_Common')) {
             $this->_db = $dsn;
         } else {
             throw new HTTP_FloodControl_Exception('Incorrect DSN.');
         }
     }
     if (PEAR::isError($this->_db)) {
         throw new HTTP_FloodControl_Exception($this->_db->getMessage(), $this->_db->getCode());
     }
 }
 /**
  * Explicitly handle an exception, should be called from an exception handler (in Flow or TypoScript)
  *
  * @param object $exception The exception to capture
  * @param array $extraData Additional data passed to the Sentry sample
  */
 public function handleException($exception, array $extraData = array())
 {
     // TODO: Handle PHP7 Throwable
     if (!$exception instanceof \Exception) {
         return;
     }
     $this->setUserContext();
     $tags = array('code' => $exception->getCode());
     if ($exception instanceof \TYPO3\Flow\Exception) {
         $extraData['referenceCode'] = $exception->getReferenceCode();
     }
     if ($this->client) {
         // safeguard; for some reasons, during cache:warmup, $this->client is not set.
         $this->client->captureException($exception, array('extra' => $extraData, 'tags' => $tags));
     }
 }
Example #21
0
 /**
  * User exception handler
  *
  * @param  object $exc hold error data
  * @return void
  **/
 public static function exceptionHandler($exc)
 {
     $errno = $exc->getCode();
     $errmsg = $exc->getMessage();
     $filename = $exc->getFile();
     $linenum = $exc->getLine();
     $debug_array = $exc->getTrace();
     $back_trace = self::_errorBacktrace($debug_array);
     $err = self::_getOutputErrorMsg($errno, $errmsg, $filename, $linenum, $back_trace);
     BizSystem::logError($errno, "ExceptionHandler", $errmsg, null, $back_trace);
     if (defined('CLI') && CLI) {
         echo $err;
     } else {
         BizSystem::clientProxy()->showErrorMessage($err, true);
     }
     exit;
 }
 /**
  * @param  object                                                $attribute
  * @param  null                                                  $format
  * @param  array                                                 $context
  * @return array|\Symfony\Component\Serializer\Normalizer\scalar
  */
 public function normalize($attribute, $format = null, array $context = [])
 {
     /**@var Attribute $attribute * */
     $normalizedAttribute = ['code' => null, 'type' => null, 'required' => null, 'labels' => null, 'parameters' => null];
     $normalizedAttribute['required'] = $attribute->isRequired();
     $normalizedAttribute['type'] = $attribute->getAttributeType();
     $normalizedAttribute['code'] = $attribute->getCode();
     $normalizedAttribute['parameters'] = ['scope' => $attribute->isScopable(), 'unique_value' => $attribute->isUnique(), 'max_characters' => $attribute->getMaxCharacters(), 'validation_rule' => $attribute->getValidationRule()];
     if ($attribute->isLocalizable()) {
         foreach ($attribute->getTranslations() as $trans) {
             $normalizedAttribute['labels'][$trans->getLocale()] = $trans->getLabel();
         }
     } else {
         $normalizedAttribute['labels'][LANGUAGE_NONE] = $attribute->getLabel();
     }
     return $normalizedAttribute;
 }
Example #23
0
File: DB.php Project: rhertzog/lcs
 /**
  * Connect to database by using the given DSN string
  *
  * @access private
  * @param  string DSN string
  * @return mixed  Object on error, otherwise bool
  */
 function _connect($dsn)
 {
     if (is_string($dsn) || is_array($dsn)) {
         $this->db = DB::Connect($dsn);
     } elseif (get_parent_class($dsn) == "db_common") {
         $this->db = $dsn;
     } elseif (DB::isError($dsn)) {
         return PEAR::raiseError($dsn->getMessage(), $dsn->getCode());
     } else {
         return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, 41, PEAR_ERROR_RETURN, null, null);
     }
     if (DB::isError($this->db) || PEAR::isError($this->db)) {
         return PEAR::raiseError($this->db->getMessage(), $this->db->getCode());
     } else {
         return true;
     }
 }
 /**
  * @param  object                                                $category
  * @param  null                                                  $format
  * @param  array                                                 $context
  * @return array|\Symfony\Component\Serializer\Normalizer\scalar
  */
 public function normalize($category, $format = null, array $context = [])
 {
     $normalizedCategory = ['code' => null, 'labels' => [], 'children' => []];
     $normalizedCategory['code'] = $category->getCode();
     /**@var Category $category * */
     foreach ($category->getTranslations() as $trans) {
         $normalizedCategory['labels'][$trans->getLocale()] = $trans->getLabel();
     }
     $childrenIds = $this->categoryRepository->getAllChildrenIds($category);
     foreach ($childrenIds as $childrenId) {
         $children = $this->categoryRepository->find($childrenId);
         foreach ($children->getTranslations() as $trans) {
             $normalizedCategory['children'][$children->getCode()]['labels'][$trans->getLocale()] = $trans->getLabel();
         }
         $normalizedCategory['children'][$children->getCode()]['parent'] = !is_null($children->getParent()) ? $children->getParent()->getCode() : null;
     }
     return $normalizedCategory;
 }
Example #25
0
 /**
  * Connect to database by using the given DSN string
  *
  * @access private
  * @param  string DSN string
  * @return mixed  Object on error, otherwise bool
  */
 function _connect($dsn)
 {
     $this->log('Auth_Container_DB::_connect() called.', AUTH_LOG_DEBUG);
     if (is_string($dsn) || is_array($dsn)) {
         $this->db = DB::Connect($dsn, $this->options['db_options']);
     } elseif (is_subclass_of($dsn, 'db_common')) {
         $this->db = $dsn;
     } elseif (DB::isError($dsn)) {
         return PEAR::raiseError($dsn->getMessage(), $dsn->getCode());
     } else {
         return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, 41, PEAR_ERROR_RETURN, null, null);
     }
     if (DB::isError($this->db) || PEAR::isError($this->db)) {
         return PEAR::raiseError($this->db->getMessage(), $this->db->getCode());
     } else {
         return true;
     }
 }
Example #26
0
 /**
  * Compares if two exception are similar.
  *
  * @param  object $actual   The actual instance.
  * @param  object $expected The expected instance.
  * @return boolean
  */
 public static function _matchException($actual, $exception)
 {
     if (!$actual) {
         return false;
     }
     if ($exception instanceof AnyException) {
         $code = $exception->getCode() ? $actual->getCode() : $exception->getCode();
         $class = get_class($actual);
     } else {
         $code = $actual->getCode();
         $class = get_class($exception);
     }
     if (get_class($actual) !== $class) {
         return false;
     }
     $sameCode = $code === $exception->getCode();
     $sameMessage = static::_sameMessage($actual->getMessage(), $exception->getMessage());
     return $sameCode && $sameMessage;
 }
Example #27
0
 /**
  * User exception handler
  *
  * @param  object $exc hold error data
  * @return void
  * */
 public static function exceptionHandler($exc)
 {
     $errno = $exc->getCode();
     $errmsg = $exc->getMessage();
     $filename = $exc->getFile();
     $linenum = $exc->getLine();
     $debug_array = $exc->getTrace();
     $back_trace = self::_errorBacktrace($debug_array);
     $err = self::_getOutputErrorMsg($errno, $errmsg, $filename, $linenum, $back_trace);
     Openbizx::$app->getLog()->logError($errno, "ExceptionHandler", $errmsg, null, $back_trace);
     if (defined('CLI') && CLI || self::$errorMode == 'text') {
         echo $err;
     } else {
         Openbizx::$app->getClientProxy()->showErrorMessage($err, true);
     }
     if (!$exc->no_exit) {
         Openbizx::$app->getClientProxy()->printOutput();
         exit;
     }
 }
Example #28
0
 /**
  * Connect to database by using the given DSN string
  *
  * @access private
  * @param  mixed  string DSN or object DB instance
  * @return mixed  Object on error, otherwise bool
  */
 function _connect(&$db)
 {
     if (is_object($db) && is_a($db, 'DB_Common')) {
         // Passed an existing instance
         $this->db =& $db;
     } else {
         if (is_string($db) || is_array($db)) {
             // Passed a DSN
             require_once BADGER_ROOT . '/core/dbAdapter/DB.php';
             $this->db =& DB::connect($db);
         } else {
             // Passed something invalid
             return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, TRANSLATION2_ERROR_CANNOT_CONNECT, PEAR_ERROR_RETURN);
         }
     }
     if (DB::isError($this->db) || PEAR::isError($this->db)) {
         return PEAR::raiseError($this->db->getMessage(), $this->db->getCode());
     }
     return true;
 }
Example #29
0
 /**
  * 框架自动执行该方法
  *
  * @param object $exceptionObj 异常消息
  */
 public function errorAction($exceptionObj)
 {
     // 根据不同的异常类型分别处理
     switch ($exceptionObj->getCode()) {
         // 找不到控制器
         case QP_Exception::EXCEPTION_NO_CONTROLLER:
             // 这里一般可以跳到自定义的 404 页面
             $this->msgbox('Page Not Found!');
             break;
             // 找不到动作
         // 找不到动作
         case QP_Exception::EXCEPTION_NO_ACTION:
             // 这里一般可以跳到当前控制器的默认动作
             $this->gotoUri($this->request->getParam('controller'), QP_Controller::DEFAULT_ACTION);
             break;
             // 其它情况都默认显示出来
         // 其它情况都默认显示出来
         default:
             $this->view->exception = $exceptionObj;
             break;
     }
 }
 /**
  * @param  object                                                $attribute
  * @param  null                                                  $format
  * @param  array                                                 $context
  * @return array|\Symfony\Component\Serializer\Normalizer\scalar
  */
 public function normalize($attribute, $format = null, array $context = [])
 {
     /**@var Attribute $attribute * */
     $normalizedAttribute = ['code' => null, 'type' => null, 'required' => null, 'labels' => null, 'parameters' => null];
     $availableLocales = [];
     $attributeAvailableLocales = $attribute->getAvailableLocales();
     if (!is_null($attributeAvailableLocales)) {
         foreach ($attribute->getAvailableLocales() as $availableLocale) {
             $availableLocales [] = $availableLocale;
         }
     }
     $normalizedAttribute['required'] = $attribute->isRequired();
     $normalizedAttribute['type'] = $attribute->getAttributeType();
     $normalizedAttribute['code'] = $attribute->getCode();
     $normalizedAttribute['parameters'] = ['scope' => $attribute->isScopable(), 'localizable' => $attribute->isLocalizable(), 'unique' => $attribute->isUnique(), 'locale_specific' => '', 'available_locales' => $availableLocales, 'default_value' => null, 'date_min' => $attribute->getDateMin(), 'date_max' => $attribute->getDateMax()];
     if ($attribute->isLocalizable()) {
         foreach ($attribute->getTranslations() as $trans) {
             $normalizedAttribute['labels'][$trans->getLocale()] = $trans->getLabel();
         }
     } else {
         $normalizedAttribute['labels'][LANGUAGE_NONE] = $attribute->getLabel();
     }
     return $normalizedAttribute;
 }