Example #1
0
 /**
  * @covers Config::getParam
  * @todo   Implement testGetParam().
  */
 public function testGetParam()
 {
     $config = array('app_key' => 'appkeyvalue', 'user_key' => 'userkeyvalue');
     $this->object->setConfig($config);
     $this->assertEquals('appkeyvalue', $this->object->getParam('app_key'));
     $this->assertEquals('userkeyvalue', $this->object->getParam('user_key'));
 }
 /**
  * The constructor of ErrorHandler
  *
  * @return void
  */
 public function __construct()
 {
     set_exception_handler(array($this, "handleException"));
     set_error_handler(array($this, "handleError"));
     $this->_config = Config::getInstance();
     $this->_errorPath = $this->_config->getParam("errorPath");
     $debugLevel = $this->_config->getParam("debugLevel");
     $this->_debugLevel = (int) intval($debugLevel);
 }
Example #3
0
 public function checkData($id = 0)
 {
     $message = '';
     if (isset($_POST['files_name'])) {
         if (!empty($_FILES['files_file']) && !empty($_FILES['files_file']['size']) && empty($id)) {
             preg_match('/\\.([a-z]{3,4})$/i', $_FILES['files_file']['name'], $ext_name);
             if (!empty($ext_name[1])) {
                 $maxFileSize = Config::getParam('files::maxSize');
                 $acceptTypes = Config::getParam('files::acceptTypes');
                 $ext_name = strtolower($ext_name[1]);
                 if ($_FILES['files_file']['size'] / 1000 > $maxFileSize) {
                     $message = 'Размер файла больше допустимого';
                 } else {
                     if (empty($acceptTypes[$ext_name]) || $acceptTypes[$ext_name] != $_FILES['files_file']['type']) {
                         $message = 'Не допустимый файл';
                     }
                 }
             } else {
                 $message = 'Не допустимый формат файла';
             }
         }
         if (empty($_POST['files_name'])) {
             $message = 'Не указано название файла';
         } else {
             if (mb_strlen($_POST['files_name'], 'UTF-8') > 255) {
                 $message = 'Название слишком длинное, нужно укоротить';
             }
         }
     }
     return $message;
 }
 function bootstrapt()
 {
     //include("\\src\\core\\classes\\Config.php");
     $Config = new Config();
     $admin = $Config->getParam('admin');
     $password = $Config->getParam('password');
     $arrFileUrl = array("C:\\xampp\\htdocs\\lesson3\\index.php", "C:\\xampp\\htdocs\\lesson3\\config.php", "C:\\xampp\\htdocs\\lesson3\\src\\core\\classes\\Config.php", "C:\\xampp\\htdocs\\lesson3\\src\\core\\classes\\Request.php", "C:\\xampp\\htdocs\\lesson3\\.htaccess");
     foreach ($arrFileUrl as $value) {
         if (file_exists($value)) {
             //var_dump("asdasd");
             continue;
         } else {
             die('Структура сайта не подлежит формату');
         }
     }
     return $this;
 }
Example #5
0
 public function __construct()
 {
     self::$DB_HOSTNAME = Config::getParam('db::DB_HOSTNAME');
     self::$DBUSER = Config::getParam('db::DBUSER');
     self::$DBPASS = Config::getParam('db::DBPASS');
     self::$DBNAME = Config::getParam('db::DBNAME');
     self::openConnect();
 }
Example #6
0
 /**
  * Sets a locale to the framework
  *
  * @param $locale string Language code
  * @return void
  */
 public static function setLocale($locale = null)
 {
     if (!self::$_init) {
         self::init();
     }
     switch ($locale) {
         case "es":
             $locale = 'es_ES';
             break;
         case "ca":
             $locale = 'ca_ES';
             break;
         case "en":
             $locale = 'en_GB';
             break;
         case "de":
             $locale = "de_DE";
             break;
         case "fr":
             $locale = "fr_FR";
             break;
         default:
             if (Session::issetData("currentLocale", "locale")) {
                 $locale = Session::get("currentLocale", "locale");
             } else {
                 $locale = self::$_config->getParam("defaultLocale");
             }
             break;
     }
     Session::set("currentLocale", $locale, "locale");
     $localeHack = self::$_config->getParam("localeHack");
     if ($localeHack != null) {
         $locale = "{$locale}{$localeHack}";
     }
     $env = "LC_ALL={$locale}";
     putenv($env);
     setlocale(LC_ALL, $locale);
     bindtextdomain("messages", self::$_localeDir);
     textdomain("messages");
 }
Example #7
0
 /**
  * Singleton for MongoDB instance.
  *
  * @return \MongoDB
  *
  * @throws Exception\DBNameNotSpecified
  * @throws Exception\ConnectionNotEstablished
  */
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         $dbName = Config::getParam('db_name');
         if (is_null($dbName)) {
             throw new Exception\DBNameNotSpecified();
         }
         try {
             self::$instance = (new \MongoClient())->selectDb($dbName);
         } catch (\Exception $e) {
             throw new Exception\ConnectionNotEstablished();
         }
     }
     return self::$instance;
 }
 public static function get($profile)
 {
     $params = array();
     $config = new Config('lib/db_profiles/' . $profile . '.ini');
     $params['dsn'] = self::getDSN($config->getParam('General', 'driver'), $config->getParam('General', 'host'), $config->getParam('General', 'port'), $config->getParam('General', 'dbname'));
     $params['username'] = $config->getParam('General', 'username');
     $params['password'] = $config->getParam('General', 'password');
     if ($config->getCategory('DriverOptions') != FALSE) {
         $params['driver_options'] = self::getDriverOptions($config->getCategory('DriverOptions'));
     } else {
         $params['driver_options'] = array();
     }
     return PDOConnection::getInstance($params);
 }
 private static function checkErrorLevel($errorNumber, $section)
 {
     if (!self::$displayLevel) {
         self::$displayLevel = Config::getParam('display', 'display_level');
     }
     if (!self::$logLevel) {
         self::$logLevel = Config::getParam('logs', 'log_level');
     }
     $setLevel = $section == 'logs' ? self::$logLevel : self::$displayLevel;
     if ($setLevel & $errorNumber) {
         return true;
     }
     if ($setLevel & E_WARNING) {
         if ($errorNumber & E_WARNING || $errorNumber & E_USER_WARNING) {
             return true;
         }
     }
     if ($setLevel & E_NOTICE) {
         if ($errorNumber & E_NOTICE || $errorNumber & E_USER_NOTICE) {
             return true;
         }
     }
     if ($setLevel & E_ERROR) {
         if ($errorNumber & E_USER_ERROR) {
             return true;
         }
     }
     return false;
 }
Example #10
0
require_once 'classes/Config.php';
require_once 'classes/EventbriteICS.php';
$config = new Config();
$params = $config->read();
if (isset($_POST['app_key'])) {
    $params['app_key'] = $_POST['app_key'];
    $params['user_key'] = $_POST['user_key'];
    $params['output_file_name'] = $_POST['output_file_name'];
    $params['timezone'] = $_POST['timezone'];
    $params['before_period'] = $_POST['before_period'];
    $params['after_period'] = $_POST['after_period'];
    $config->setConfig($params);
    $config->write();
}
// $config->read();
$app_key = $config->getParam('app_key');
$user_key = $config->getParam('user_key');
$output_file_name = $config->getParam('output_file_name');
$before_period = $config->getParam('before_period');
$after_period = $config->getParam('after_period');
// Get the user data ...
$eb_client = new Eventbrite(array('app_key' => $app_key, 'user_key' => $user_key));
try {
    $user = $eb_client->user_get();
} catch (Exception $ex) {
    // No events means the key is no good
    // This is a validation that should be reported, but for now
    // we just clear the params ...
    $message = $ex->getMessage();
}
?>
 /**
  * Processes the request of this REST server
  *
  * @access private
  * @return void
  */
 private function _process()
 {
     $action = "";
     $method = "";
     $object = null;
     $objectMap = null;
     $callParams = array();
     $serviceName = $this->_urlParts[0];
     if (empty($serviceName)) {
         $this->serviceNameEmpty();
         return;
     }
     $parameters = array();
     $params = array_splice($this->_urlParts, 1);
     if (count($params) % 2 != 0) {
         $params[] = "null";
     }
     for ($i = 0; $i < count($params); $i += 2) {
         $parameters[$params[$i]] = array("value" => $params[$i + 1]);
     }
     if (count($this->_dispatchMap) > 0) {
         if ($serviceName == "system") {
             $this->system($params);
             return true;
         }
         if ($serviceName == "login") {
             if (count($params) % 4 != 0) {
                 return $this->unauthorized();
             }
             return $this->_restLogin($params);
         }
         if ($serviceName == "logout") {
             return $this->_restLogout();
         }
         foreach ($this->_dispatchMap as $dispatchObject) {
             foreach ($dispatchObject->getObjectApi() as $map) {
                 if ($map["serviceName"] == $serviceName && $map["method"] == $this->_method) {
                     $object = $dispatchObject;
                     $objectMap = $map;
                     break;
                 }
             }
         }
         if ($object != null) {
             // Process the FWRestAdapter
             if ($objectMap != null) {
                 if (isset($objectMap["in"])) {
                     $pars = array_keys($objectMap["in"]);
                     foreach ($pars as $par) {
                         if (isset($parameters[$par])) {
                             $value = $parameters[$par]["value"];
                             $type = $objectMap["in"][$par];
                             if ($this->_checkParam($type, $value)) {
                                 $callParams[$par] = $value;
                             }
                         }
                     }
                 }
                 $method = $objectMap["action"];
                 $auth = $objectMap["auth"];
                 if ($auth != false) {
                     $authenticationMethod = (string) $this->_config->getParam("restAuthMethod");
                     $isAuthenticated = Session::get("authentication", "REST");
                     if ($isAuthenticated) {
                         if ($authenticationMethod == "login") {
                             $role = false;
                             $role = Session::get("role", "REST");
                             if ($role != $auth) {
                                 trigger_error("Error: Acceding without a valid role to the ... ", E_USER_ERROR);
                                 return $this->unauthorized(0);
                             }
                         } else {
                             $key = Session::get("key", "REST");
                         }
                     } else {
                         return $this->unauthorized();
                     }
                 }
             }
             if (($_SERVER["REQUEST_METHOD"] == "POST" || $_SERVER["REQUEST_METHOD"] == "PUT") && isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > 0) {
                 $this->_requestData = '';
                 $httpContent = fopen('php://input', 'r');
                 while ($data = fread($httpContent, 1024)) {
                     $this->_requestData .= $data;
                 }
                 fclose($httpContent);
                 Session::set("data", $this->_requestData, "REST");
                 $result = $object->{$method}($callParams, $this->_requestData);
                 header('Content-type: text/xml');
                 print $result;
                 exit(0);
             }
             $result = $object->{$method}($callParams);
             header('Content-type: text/xml');
             print $result;
             exit(0);
         } else {
             return $this->notFound();
         }
     } else {
         return $this->notFound();
     }
 }
Example #12
0
 /**
  * @return bool
  * @throws AppException
  */
 protected function isCurrentLanguageDefaultLanguage()
 {
     return Config::getLn() == Config::getParam(Config::DEFAULT_LN);
 }