Example #1
0
 /**
  * Constructor
  *
  * @param   string|RFormatter $format      Output format ID, or formatter instance defaults to 'html'
  */
 public function __construct($format = 'html')
 {
     static $didIni = false;
     if (!$didIni) {
         $didIni = true;
         foreach (array_keys(static::$config) as $key) {
             $iniVal = get_cfg_var('ref.' . $key);
             print_r($iniVal);
             if ($iniVal !== false) {
                 static::$config[$key] = $iniVal;
             }
         }
     }
     if ($format instanceof RFormatter) {
         $this->fmt = $format;
     } else {
         $format = __NAMESPACE__ . '\\' . (isset(static::$config['formatters'][$format]) ? static::$config['formatters'][$format] : 'R' . ucfirst($format) . 'Formatter');
         if (!class_exists($format, true)) {
             throw new \Exception(sprintf('%s class not found', $format));
         }
         $this->fmt = new $format();
     }
     if (static::$env) {
         return;
     }
     static::$env = array('is54' => version_compare(PHP_VERSION, '5.4') >= 0, 'is546' => version_compare(PHP_VERSION, '5.4.6') >= 0, 'is56' => version_compare(PHP_VERSION, '5.6') >= 0, 'curlActive' => function_exists('curl_version'), 'mbStr' => function_exists('mb_detect_encoding'), 'supportsDate' => strncasecmp(PHP_OS, 'WIN', 3) !== 0 || version_compare(PHP_VERSION, '5.3.10') >= 0);
 }
Example #2
0
 /**
  * Instantiates this class
  *
  * @param int $id ID of the attachment
  */
 public function __construct($id)
 {
     // Check if post exists
     if (!is_string(get_post_status($id))) {
         throw new \Exception("Post does not exist");
     }
     // Check if post is an attachment
     if (get_post_type($id) != 'attachment') {
         throw new \Exception("Target post is not an attachment");
     }
     // Check if attachment have a file path to use
     $this->partial_path = get_post_meta($id, '_wp_attached_file', true);
     if (!$this->partial_path) {
         throw new \Exception("Target post does not have a file path to be used");
     }
     // Collect environment information if not already available
     if (is_null(static::$env)) {
         static::$env = static::__getEnvInfo();
     }
     // Get WordPress meta data
     $default_wordpress_meta = ['sizes' => []];
     $this->wordpress_meta = get_post_meta($id, '_wp_attachment_metadata', true) ?: $default_wordpress_meta;
     // Get plugin meta data
     $default_plugin_meta = ['sizes' => []];
     $plugin_meta_json = get_post_meta($id, Config::ATTACHMENT_META_KEY, true);
     $this->plugin_meta = $plugin_meta_json ? json_decode($plugin_meta_json, true) : $default_plugin_meta;
     // Store post id
     $this->id = $id;
 }
Example #3
0
 public static function loadEnv($filepath, array $options = [])
 {
     $loader = (new Loader($filepath))->raiseExceptions(true)->parse();
     if (!empty($options)) {
         extract($options);
     }
     if (isset($expect) && is_array($expect)) {
         $loader = $loader->expect($expect);
     }
     static::$env = $loader->toArray();
 }
Example #4
0
 /**
  * Detect environment
  *
  * By default check
  *
  * @return string env
  */
 public static function detectEnvironment($request = null)
 {
     if (!empty(static::$env)) {
         return static::$env;
     }
     $rules = self::get('env');
     $request = $request ? $request : Request::createFromGlobals();
     $host = $request->getHost();
     foreach ($rules as $env => $rule) {
         if (is_callable($rule)) {
             static::$env = $env;
         } elseif (preg_match($rule, $host)) {
             static::$env = $env;
             break;
         }
     }
     static::loadEnvironment(static::$env);
     return static::$env;
 }
Example #5
0
 /**
  * Generate data for ApiTestCaseV2
  *
  * @param string $fixtures patch to fixtures directory
  * @return array
  * @throws \Scalr\System\Config\Exception\YamlException
  */
 public static function dataFixtures($fixtures)
 {
     // set config
     static::$testUserId = \Scalr::config('scalr.phpunit.userid');
     static::$user = User::findPk(static::$testUserId);
     static::$testEnvId = \Scalr::config('scalr.phpunit.envid');
     static::$env = Environment::findPk(static::$testEnvId);
     $data = [];
     foreach (new DirectoryIterator($fixtures) as $fileInfo) {
         if ($fileInfo->isFile()) {
             $class = __NAMESPACE__ . '\\' . ucfirst($fileInfo->getBasename('.yaml'));
             if (class_exists($class)) {
                 /* @var $object TestDataFixtures */
                 $object = new $class(Yaml::load($fileInfo->getPathname())->toArray());
                 $object->prepareTestData();
                 $data = array_merge($data, $object->preparePathInfo());
             }
         }
     }
     return $data;
 }
Example #6
0
 /**
  * Initializes the framework.  This can only be called once.
  *
  * @access	public
  * @return	void
  */
 public static function init($config)
 {
     if (static::$initialized) {
         throw new \Exception("You can't initialize Fuel more than once.");
     }
     register_shutdown_function('fuel_shutdown_handler');
     set_exception_handler('fuel_exception_handler');
     set_error_handler('fuel_error_handler');
     // Start up output buffering
     ob_start();
     static::$profiling = isset($config['profiling']) ? $config['profiling'] : false;
     if (static::$profiling) {
         \Profiler::init();
         \Profiler::mark(__METHOD__ . ' Start');
     }
     static::$cache_dir = isset($config['cache_dir']) ? $config['cache_dir'] : APPPATH . 'cache/';
     static::$caching = isset($config['caching']) ? $config['caching'] : false;
     static::$cache_lifetime = isset($config['cache_lifetime']) ? $config['cache_lifetime'] : 3600;
     if (static::$caching) {
         static::$path_cache = static::cache('Fuel::path_cache');
     }
     \Config::load($config);
     static::$_paths = array_merge(\Config::get('module_paths', array()), array(APPPATH, COREPATH));
     static::$is_cli = (bool) (php_sapi_name() == 'cli');
     if (!static::$is_cli) {
         if (\Config::get('base_url') === null) {
             \Config::set('base_url', static::generate_base_url());
         }
         \Uri::detect();
     }
     // Run Input Filtering
     \Security::clean_input();
     static::$env = \Config::get('environment');
     static::$locale = \Config::get('locale');
     //Load in the packages
     foreach (\Config::get('always_load.packages', array()) as $package) {
         static::add_package($package);
     }
     // Set some server options
     setlocale(LC_ALL, static::$locale);
     // Always load classes, config & language set in always_load.php config
     static::always_load();
     static::$initialized = true;
     if (static::$profiling) {
         \Profiler::mark(__METHOD__ . ' End');
     }
 }
Example #7
0
 /**
  *
  */
 private function detectEnvironment()
 {
     static::$env = ['developing' => env('APP_ENV', 'PRODUCTION') !== 'PRODUCTION', 'app_key' => env('APP_KEY', '[set me]'), 'debugging' => env('DEBUG', FALSE), 'testing' => env('TESTING', FALSE)];
 }
Example #8
0
 /**
  * Add test environment, test Acl, setups test user, environment and API key
  */
 public static function setUpBeforeClass()
 {
     if (!Scalr::getContainer()->config->defined('scalr.phpunit.apiv2')) {
         static::markTestIncomplete('phpunit apiv2 configurations is invalid');
     }
     if (Scalr::getContainer()->config->defined('scalr.phpunit.apiv2.params.max_results')) {
         static::$maxResults = Scalr::config('scalr.phpunit.apiv2.params.max_results');
     }
     static::$testUserId = Scalr::config('scalr.phpunit.apiv2.userid');
     static::$user = User::findPk(static::$testUserId);
     static::$testUserType = static::$user->type;
     static::$testEnvId = Scalr::config('scalr.phpunit.apiv2.envid');
     static::$env = Environment::findPk(static::$testEnvId);
     if (empty(static::$user) || empty(static::$env)) {
         static::markTestIncomplete('Either test environment or user is invalid.');
     }
     $apiKeyName = static::getTestName();
     $apiKeyEntity = ApiKeyEntity::findOne([['name' => $apiKeyName], ['userId' => static::$testUserId]]);
     if (empty($apiKeyEntity)) {
         $apiKeyEntity = new ApiKeyEntity(static::$testUserId);
         $apiKeyEntity->name = $apiKeyName;
         $apiKeyEntity->save();
     }
     static::$apiKeyEntity = $apiKeyEntity;
     static::$defaultAcl = Scalr::getContainer()->acl;
     static::$data = [static::$testEnvId => []];
     if (empty(static::$fullAccessAcl)) {
         static::$fullAccessAcl = new ApiTestAcl();
         static::$fullAccessAcl->setDb(Scalr::getContainer()->adodb);
         static::$fullAccessAcl->createTestAccountRole(static::$user->getAccountId(), static::getTestName(ApiFixture::ACL_FULL_ACCESS), ApiTestAcl::ROLE_ID_FULL_ACCESS);
         static::$fullAccessAcl->aclType = ApiFixture::ACL_FULL_ACCESS;
     }
     if (empty(static::$readOnlyAccessAcl)) {
         static::$readOnlyAccessAcl = new ApiTestAcl();
         static::$readOnlyAccessAcl->setDb(Scalr::getContainer()->adodb);
         static::$readOnlyAccessAcl->createTestAccountRole(static::$user->getAccountId(), static::getTestName(ApiFixture::ACL_READ_ONLY_ACCESS), ApiTestAcl::ROLE_ID_READ_ONLY_ACCESS);
         static::$readOnlyAccessAcl->aclType = ApiFixture::ACL_READ_ONLY_ACCESS;
     }
 }
Example #9
0
 /**
  * Initializes the framework.  This can only be called once.
  *
  * @access	public
  * @return	void
  */
 public static function init($config)
 {
     \Config::load($config);
     if (static::$initialized) {
         throw new \Fuel_Exception("You can't initialize Fuel more than once.");
     }
     register_shutdown_function('fuel_shutdown_handler');
     set_exception_handler('fuel_exception_handler');
     set_error_handler('fuel_error_handler');
     // Start up output buffering
     ob_start(\Config::get('ob_callback', null));
     static::$profiling = \Config::get('profiling', false);
     if (static::$profiling) {
         \Profiler::init();
         \Profiler::mark(__METHOD__ . ' Start');
     }
     static::$cache_dir = \Config::get('cache_dir', APPPATH . 'cache/');
     static::$caching = \Config::get('caching', false);
     static::$cache_lifetime = \Config::get('cache_lifetime', 3600);
     if (static::$caching) {
         static::$path_cache = static::cache('Fuel::path_cache');
     }
     // set a default timezone if one is defined
     static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get();
     date_default_timezone_set(static::$timezone);
     // set the encoding and locale to use
     static::$encoding = \Config::get('encoding', static::$encoding);
     static::$locale = \Config::get('locale', static::$locale);
     static::$_paths = array(APPPATH, COREPATH);
     if (!static::$is_cli) {
         if (\Config::get('base_url') === null) {
             \Config::set('base_url', static::generate_base_url());
         }
         \Uri::detect();
     }
     // Run Input Filtering
     \Security::clean_input();
     static::$env = \Config::get('environment');
     \Event::register('shutdown', 'Fuel::finish');
     //Load in the packages
     foreach (\Config::get('always_load.packages', array()) as $package => $path) {
         is_string($package) and $path = array($package => $path);
         static::add_package($path);
     }
     // Load in the routes
     \Config::load('routes', true);
     \Router::add(\Config::get('routes'));
     // Set  locale
     static::$locale and setlocale(LC_ALL, static::$locale);
     // Always load classes, config & language set in always_load.php config
     static::always_load();
     static::$initialized = true;
     if (static::$profiling) {
         \Profiler::mark(__METHOD__ . ' End');
     }
 }
Example #10
0
 /**
  * Helper method to determine if track calls should be respected
  *
  * It is possible to filter tracking calls based on environment
  * and this method will make sure that is respected
  * @return bool
  **/
 protected static function isTracking()
 {
     if (($env = static::$_config['env']) && $env === '*') {
         return true;
     }
     if (!static::$env) {
         static::$env = Environment::get();
     }
     return is_array($env) ? in_array(static::$env, $env) : static::$env === $env;
 }
Example #11
0
 /**
  * Constructor
  *
  * @param   string|RFormatter $format      Output format ID, or formatter instance defaults to 'html'
  */
 public function __construct($format = 'html')
 {
     if ($format instanceof RFormatter) {
         $this->fmt = $format;
     } else {
         $format = isset(static::$config['formatters'][$format]) ? static::$config['formatters'][$format] : 'R' . ucfirst($format) . 'Formatter';
         if (!class_exists($format, false)) {
             throw new \Exception(sprintf('%s class not found', $format));
         }
         $this->fmt = new $format();
     }
     if (static::$env) {
         return;
     }
     static::$env = array('is54' => version_compare(PHP_VERSION, '5.4') >= 0, 'is546' => version_compare(PHP_VERSION, '5.4.6') >= 0, 'curlActive' => function_exists('curl_version'), 'mbStr' => function_exists('mb_detect_encoding'), 'supportsDate' => strncasecmp(PHP_OS, 'WIN', 3) !== 0 || version_compare(PHP_VERSION, '5.3.10') >= 0);
 }
Example #12
0
 /**
  * **Detect and configure the environment.**
  *
  * @throws ConfigurationException
  */
 private function detect_environment()
 {
     static::$env = ['developing' => env('APP_ENV', 'PRODUCTION') !== 'PRODUCTION', 'app_key' => env('APP_KEY', '[set me]'), 'debugging' => env('DEBUG', FALSE), 'testing' => env('TESTING', FALSE)];
     // register this factory
     Forge::set([static::class, 'AppFactory'], $this);
 }
Example #13
0
 /**
  * Generate data for ApiTest
  *
  * @param string $fixtures patch to fixtures directory
  * @param string $type api specifications type
  * @return array
  * @throws \Scalr\System\Config\Exception\YamlException
  */
 public static function loadData($fixtures, $type)
 {
     // set config
     static::$testUserId = \Scalr::config('scalr.phpunit.apiv2.userid');
     static::$user = User::findPk(static::$testUserId);
     static::$testEnvId = \Scalr::config('scalr.phpunit.apiv2.envid');
     static::$env = Environment::findPk(static::$testEnvId);
     $data = [];
     foreach (new ApiFixtureIterator(new DirectoryIterator($fixtures), $type) as $fileInfo) {
         $class = __NAMESPACE__ . '\\' . ucfirst($fileInfo->getBasename('.yaml'));
         try {
             /* @var $object ApiFixture */
             $object = new $class(Yaml::load($fileInfo->getPathname())->toArray(), $type);
             $object->prepareTestData();
             $pathInfo = $object->preparePathInfo();
         } catch (Exception $e) {
             $pathInfo = [array_merge([$class, $e, null, null, null], static::$defaultOperation)];
         }
         $data = array_merge($data, $pathInfo);
     }
     return $data;
 }
Example #14
0
 /**
  * Get or set the system environment
  *
  * @param string $environment The system environment to be set
  * @return string
  */
 public static function env($environment = null)
 {
     if ($environment) {
         static::$env = $environment;
     }
     return static::$env;
 }
Example #15
0
 /**
  * Setups test user, environment and API key
  *
  * @beforeClass
  *
  * @throws \Scalr\Exception\ModelException
  */
 public static function setUpBeforeClass()
 {
     static::$testUserId = \Scalr::config('scalr.phpunit.userid');
     static::$user = User::findPk(static::$testUserId);
     static::$testEnvId = \Scalr::config('scalr.phpunit.envid');
     static::$env = Environment::findPk(static::$testEnvId);
     $apiKeyName = static::getTestName();
     $apiKeyEntity = ApiKeyEntity::findOne([['name' => $apiKeyName], ['userId' => static::$testUserId]]);
     if (empty($apiKeyEntity)) {
         $apiKeyEntity = new ApiKeyEntity(static::$testUserId);
         $apiKeyEntity->name = $apiKeyName;
         $apiKeyEntity->save();
     }
     static::$apiKeyEntity = $apiKeyEntity;
 }
Example #16
0
 public static function setEnvironment(Environment $env)
 {
     static::$env = $env;
 }
Example #17
0
 /**
  * Setups test user, environment and API key
  *
  * @throws \Scalr\Exception\ModelException
  */
 public static function setUpBeforeClass()
 {
     static::$testUserId = \Scalr::config('scalr.phpunit.userid');
     static::$user = User::findPk(static::$testUserId);
     static::$testEnvId = \Scalr::config('scalr.phpunit.envid');
     static::$env = Environment::findPk(static::$testEnvId);
     if (empty(static::$user) || empty(static::$env)) {
         static::markTestIncomplete('Either test environment or user is invalid.');
     }
     $apiKeyName = static::getTestName();
     $apiKeyEntity = ApiKeyEntity::findOne([['name' => $apiKeyName], ['userId' => static::$testUserId]]);
     if (empty($apiKeyEntity)) {
         $apiKeyEntity = new ApiKeyEntity(static::$testUserId);
         $apiKeyEntity->name = $apiKeyName;
         $apiKeyEntity->save();
     }
     static::$apiKeyEntity = $apiKeyEntity;
     static::changeLoggerConfiguration();
 }
Example #18
0
 /**
  * Class constructor
  *
  * @param object $constants
  * @param object $cooker
  * @param object $injector
  * @param object $crypt
  * @param object $databaseService
  * @param object $repository
  * @param object $eventDispatcher
  *
  */
 public function __construct(Constants $constants, CookerInterface $cooker, Injector $injector, CryptInterface $crypt, DatabaseServiceInterface $databaseService, SessionHandlerInterface $repository, Dispatcher $eventDispatcher)
 {
     static::$constants = $constants;
     static::$injector = $injector;
     static::$repository = $repository;
     static::$cooker = $cooker;
     static::$eventDispatcher = $eventDispatcher;
     static::$crypt = $crypt;
     static::$eventDispatcher->setInstance(static::getInstance());
     static::$model = $databaseService->get(static::$injector->get('db'));
     static::$env = php_sapi_name();
     static::setSession(static::$repository);
 }
Example #19
0
 public static function init()
 {
     //Sanitize inputs
     //.Remove magic quotes
     if (magic_quotes()) {
         $magics = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
         foreach ($magics as &$magic) {
             $magic = array_strip_slashes($magic);
         }
     }
     //.Unset globals
     foreach (array($_GET, $_POST) as $global) {
         if (is_array($global)) {
             foreach ($global as $k => $v) {
                 global ${$k};
                 ${$k} = NULL;
             }
         }
     }
     //.Clean post input
     array_map(function ($v) {
         return Request::clearValue($v);
     }, $_POST);
     //Remove /public/index.html from path_info..
     foreach (array("PATH_INFO", "ORIG_PATH_INFO", "PATH_TRANSLATED", "PHP_SELF") as $k) {
         if (isset($_SERVER[$k])) {
             $_SERVER[$k] = str_replace("/public/index.html", "/", $_SERVER[$k]);
         }
     }
     static::$server = $_SERVER;
     static::$get = $_GET;
     static::$post = $_POST;
     $_GET = null;
     $_POST = null;
     $_SERVER = null;
     $_REQUEST = null;
     //Detect environment
     $list = (require J_PATH . "config" . DS . "environments" . EXT);
     $env = "";
     $envWithWildcard = array_first($list);
     $hosts = array(array_get(static::$server, "HTTP_HOST", "localhost"), array_get(static::$server, "SERVER_NAME", "localhost"), array_get(static::$server, "SERVER_ADDR", "localhost"), gethostname());
     foreach ($hosts as $host) {
         foreach ($list as $k => $v) {
             foreach ((array) $v as $hostname) {
                 if ($hostname != "" && $hostname == $host) {
                     $env = $k;
                     break;
                 } else {
                     if ($hostname == "*") {
                         $envWithWildcard = $k;
                     }
                 }
             }
             if (!empty($env)) {
                 break;
             }
         }
         if (!empty($env)) {
             break;
         }
     }
     if (empty($env)) {
         $env = $envWithWildcard;
     }
     static::$env = $env;
     //Detect method
     $method = strtoupper(array_get(static::$server, "REQUEST_METHOD", "GET"));
     if ($method == "POST" && static::hasReq("_method")) {
         $methodReq = static::req("_method", "POST");
         if (array_search($methodReq, static::$availableMethods) !== false) {
             $method = $methodReq;
         }
     }
     static::$method = $method;
 }