$regenerator = function ($delete) { $_SESSION = []; session_regenerate_id($delete); return session_id(); }; return new Environment\Session($_SESSION, session_id(), 'skyhook', $regenerator); }); // Register Environment Singletons foreach (array('Get' => &$_GET, 'Post' => &$_POST, 'Server' => &$_SERVER, 'PostFiles' => &$_FILES, 'Cookie' => &$_COOKIE) as $class => $glbl) { $c = "Environment\\" . $class; Container::registerSingleton($c, function () use($c, $glbl) { return new $c($glbl); }); } $cookies = Container::dispense("Environment\\Cookie"); if (isset($cookies['lang']) && Localization::localePresent($cookies['lang'])) { Localization::setLocale($cookies['lang']); } Container::registerSingleton('Environment\\RequestHeaders', function () { $headers = getallheaders(); return new Environment\RequestHeaders($headers); }); foreach (array('Delete', 'Put') as $wrapper) { Container::registerSingleton($wrapper, function () use($wrapper) { $server = Container::dispense(Environment\Server); $nsed = "Environment\\" . $wrapper; $wrapped = $nsed::buildHelper($server); return new $nsed($wrapped); }); } Container::registerSingleton('DB', function () {
public function getErrors(Post $post) { $i18n = Localization::getTranslator(); //TODO: implement range checking on modifier values, and static pricing $walletSettings = []; if (empty($post['wallet']['id'])) { $walletSettings[] = ['id' => '#wallet-id-error', 'error' => $i18n->_('A valid Blockchain.info wallet id is required.')]; } if (empty($post['wallet']['mainPass'])) { $walletSettings[] = ['id' => '#wallet-mainPass-error', 'error' => $i18n->_('Your respective Blockchain.info password is required.')]; } if (empty($post['wallet']['fromAddress'])) { $walletSettings[] = ['id' => '#wallet-fromAddress-error', 'error' => $i18n->_('An address controlled by your Blockchain.info wallet is required to send from.')]; } elseif (!AddressUtility::checkAddress($post['wallet']['fromAddress'])) { $walletSettings[] = ['id' => '#wallet-fromAddress-error', 'error' => $i18n->_('A valid Bitcoin address is required.')]; } $emailUser = @$post['email']['username']; $emailSettings = []; if (empty($emailUser)) { $emailSettings[] = ['id' => '#email-username-error', 'error' => $i18n->_('A valid email address is required.')]; } elseif (filter_var($emailUser, FILTER_VALIDATE_EMAIL) !== $emailUser) { $emailSettings[] = ['id' => '#email-username-error', 'error' => $i18n->_('Email address entered is not valid.')]; } if (empty($post['email']['password'])) { $emailSettings[] = ['id' => '#email-password-error', 'error' => $i18n->_('Email password is required.')]; } $passwordSettings = []; if (strlen(@$post['admin_password']) < 5) { $passwordSettings[] = ['id' => '#password-error', 'error' => $i18n->_('Minimum password length is 5 characters.')]; } if (@$post['admin_password'] !== @$post['confirm_admin_password']) { $passwordSettings[] = ['id' => '#password-error', 'error' => $i18n->_('Admin passwords must match')]; } $transactionSettings = []; if (isset($post['transactions']['maximum'])) { if (!preg_match('#^[0-9]+$#', $post['transactions']['maximum'])) { $transactionSettings[] = ['id' => '#maximum-errors', 'error' => $i18n->_('Maximum transaction value must be a positive integer.')]; } } $localeSettings = []; if (isset($post['locale'])) { if (!Localization::localePresent($post['locale'])) { $transactionSettings[] = ['id' => '#locale-errors', 'error' => $i18n->_('Unkown Locale.')]; } } $errors = []; if (!empty($transactionSettings)) { $errors['#locale-settings'] = $localeSettings; } if (!empty($transactionSettings)) { $errors['#transaction-settings'] = $transactionSettings; } if (!empty($passwordSettings)) { $errors['#password-settings'] = $passwordSettings; } if (!empty($pricingSettings)) { $errors['#pricing-settings'] = self::getPricingErrors($post); } if (!empty($walletSettings)) { $errors['#wallet-settings'] = $walletSettings; } if (!empty($emailSettings)) { $errors['#email-settings'] = $emailSettings; } return $errors; }