Exemple #1
0
 /**
  * @return static
  */
 public static function get()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new static();
         self::$_instance->init();
     }
     return self::$_instance;
 }
Exemple #2
0
 /**
  * @return static
  */
 public static function instance()
 {
     if (null === static::$instance) {
         static::$instance = new static();
         static::$instance->init();
     }
     return static::$instance;
 }
 /**
  *  初始化
  */
 static function init()
 {
     if (!isset(static::$init)) {
         static::$init = new Static();
     }
     return static::$init;
 }
Exemple #4
0
 protected static function init()
 {
     static::$latin_map[' '] = '-';
     static::$latin_map['/'] = '-';
     static::$latin_map["'"] = '';
     static::$latin_map['&'] = '';
     static::$replace_map = array("search" => array_keys(static::$latin_map), "replace" => array_values(static::$latin_map));
     static::$init = true;
 }
Exemple #5
0
 public static function Initialize()
 {
     static $instance = NULL;
     if ($instance === NULL) {
         $instance = new static();
         $instance->init();
     }
     return $instance;
 }
Exemple #6
0
 public static function getInstance($control)
 {
     if (empty(static::$modules)) {
         $_Instance = new static();
         if (is_callable(array($_Instance, 'init'))) {
             $_Instance->init();
         }
         static::$modules =& M();
     }
     return $_Instance;
 }
Exemple #7
0
 /**
  * A method for generating a free-form enum at runtime.
  * Simply pass this method a list of values and BAM you have an enum.
  * No need for all that class extending nonsense here.
  *
  * @param string This accepts multiple arguments
  * @return Enum instance
  */
 public static function create($val)
 {
     $c = new static();
     $c->enum = [];
     $c->values = [];
     foreach (func_get_args() as $v) {
         if (!in_array($v, $c->enum)) {
             $c->enum[] = $v;
         }
     }
     $c->init();
     return $c;
 }
 /**
  * @param $post
  * @return static
  */
 public static function getById($post)
 {
     $instance = new static($post);
     if (is_numeric($post)) {
         $instance->id = absint($post);
         $instance->post = get_post($instance->id);
     } elseif ($post instanceof WA_Project) {
         $instance->id = absint($post->id);
         $instance->post = $post;
     } elseif ($post instanceof WP_Post || isset($post->ID)) {
         $instance->id = absint($post->ID);
         $instance->post = $post;
     }
     $instance->init();
     return $instance;
 }
Exemple #9
0
 /**
  * Ensure the session data is loaded into cache.
  *
  * @return void
  */
 protected static function init()
 {
     if (static::$init) {
         return;
     }
     static::$init = true;
     if (!static::$name) {
         throw new \Exception("Cannot start session, no name has been specified");
     }
     session_cache_limiter(false);
     session_name(static::$name);
     session_start();
     # Grab the sessions data to respond to get()
     static::$data = $_SESSION;
     # Remove the lock from the session file
     session_write_close();
 }
 public static function clearEventsCache($iblockId)
 {
     $ec = new static();
     $ec->init(array());
     $ec->ClearCache($ec->cachePath . 'events/' . intval($iblockId) . '/');
 }
 public static function finalize()
 {
     // Make sure the autoloader is initialized
     if (!static::isInit()) {
         return true;
     }
     // Unregister the autoloader function
     if (spl_autoload_unregister(__CLASS__ . '::loadClass') === false) {
         return false;
     }
     // Clear the list of loaders
     static::removeAllLoaders();
     // Set the initialization flag, return the result
     static::$init = false;
     return true;
 }
 /**
  * Factory
  */
 public static function factory()
 {
     $instance = new static();
     $instance->init();
     return $instance;
 }
 /**
  * Set core initialization status
  * 
  * @return void
  */
 public function init()
 {
     static::$init = TRUE;
 }
Exemple #14
0
 /**
  * Launches an app actor
  * @param integer  $id
  * @param callable $handler
  * @param array    $config
  */
 public static function launch($id, callable $handler, array $config = [])
 {
     $app = new static($id, $handler, $config);
     $app->init();
     $app->run();
 }
Exemple #15
0
 /**
  * Load settings.
  */
 protected static function init()
 {
     if (!static::$init) {
         // Make sure session counting is initialised, even if we don't listen to
         // any request init event (conf session_counters).
         static::sessionCounters();
         // Find real path, and document root (if possible), for removal from
         // absolute paths.
         // The reason document root may differ from real path is symbolic links.
         if ($paths = static::configGet('inspect', 'paths')) {
             // Last bucket is path length.
             static::$pathLength = array_pop($paths);
             static::$paths = $paths;
         } else {
             $docRoot = '';
             $le0 = static::mb_strlen($realPath = static::docRoot());
             // getcwd().
             $le1 = !empty($_SERVER['SCRIPT_FILENAME']) ? static::mb_strlen($docRoot = dirname($_SERVER['SCRIPT_FILENAME'])) : 0;
             // Find longest path.
             $osNix = DIRECTORY_SEPARATOR == '/';
             // And remove drive C:, for Windows.
             static::$pathLength = ($le0 < $le1 ? $le0 : $le1) - ($osNix ? 0 : 2);
             static::$paths = $paths = array($osNix ? '/^' . preg_quote($realPath, '/') . '\\//' : '/^(' . $realPath[0] . '\\:)?' . str_replace('/', '[\\\\\\/]', preg_quote(str_replace('\\', '/', static::mb_substr($realPath, 2)))) . '[\\\\\\/]/i');
             if ($le1 && $docRoot != $realPath) {
                 static::$paths[] = $osNix ? '/^' . preg_quote($docRoot, '/') . '\\//' : '/^(' . $docRoot[0] . '\\:)?' . str_replace('/', '[\\\\\\/]', preg_quote(str_replace('\\', '/', static::mb_substr($docRoot, 2)))) . '[\\\\\\/]/i';
             }
             // Save, they are kind of expensive to establish.
             $paths[] = static::$pathLength;
             static::configSet('inspect', 'paths', $paths);
         }
         unset($paths);
         // Establish output max length.
         static::$outputMax = static::outputMax();
         // Establish request time start.
         $t = static::requestTimeMilli();
         // Establish max execution time abort - if any max at all.
         if (static::$maxExecTime = $max = ini_get('max_execution_time')) {
             static::$maxExecTimeout = floor($t / 1000) + floor($max * static::configGet('inspect', 'exectime_percent', 90) / 100);
         } else {
             static::$maxExecTimeout = -1;
         }
         // Prepare default options - make get options equal file options if CLI
         // request.
         if (PHP_SAPI === 'cli') {
             // Array append.
             static::$defaultsByTarget['get'] += static::$defaultsByTarget['file'];
         }
         static::$init = TRUE;
     }
 }
Exemple #16
0
 /**
  * kick start to just fetch the config
  * @return array
  */
 public static function resolveConfiguration()
 {
     static::$init = true;
     $self = new static();
     static::$init = false;
     $conf = array('table' => $self->getTable(), 'fieldConf' => $self->getFieldConfiguration(), 'db' => $self->db, 'fluid' => $self->fluid, 'primary' => $self->primary);
     unset($self);
     return $conf;
 }
Exemple #17
0
 /**
  * Creates and returns a non-empty model.
  * This function is useful to centralize the creation of non-empty models,
  * since isNewRecord must set to null by passing non_empty.
  */
 private static function _create_model(array $data)
 {
     self::$preventInit = true;
     self::$skipDefaultAttributes = true;
     $model = new static();
     $model->attributes = $data;
     # Check for primary_key and set init_attrs.
     if (!static::table()->primaryKey()) {
         $model->storedAttributes = $data;
     }
     $model->isNewRecord = false;
     $model->_register();
     $model->init();
     return $model;
 }
Exemple #18
0
    /**
     * Create new event.
     *
     * The optional data keys as:
     * 1/ objectid - the id of the object specified in class name
     * 2/ context - the context of this event
     * 3/ other - the other data describing the event, can not contain objects
     * 4/ relateduserid - the id of user which is somehow related to this event
     *
     * @param array $data
     * @return \core\event\base returns instance of new event
     *
     * @throws \coding_exception
     */
    public static final function create(array $data = null) {
        global $USER, $CFG;

        $data = (array)$data;

        /** @var \core\event\base $event */
        $event = new static();
        $event->triggered = false;
        $event->restored = false;
        $event->dispatched = false;

        // Set static event data specific for child class.
        $event->init();

        if (isset($event->data['level'])) {
            if (!isset($event->data['edulevel'])) {
                debugging('level property is deprecated, use edulevel property instead', DEBUG_DEVELOPER);
                $event->data['edulevel'] = $event->data['level'];
            }
            unset($event->data['level']);
        }

        // Set automatic data.
        $event->data['timecreated'] = time();

        // Set optional data or use defaults.
        $event->data['objectid'] = isset($data['objectid']) ? $data['objectid'] : null;
        $event->data['courseid'] = isset($data['courseid']) ? $data['courseid'] : null;
        $event->data['userid'] = isset($data['userid']) ? $data['userid'] : $USER->id;
        $event->data['other'] = isset($data['other']) ? $data['other'] : null;
        $event->data['relateduserid'] = isset($data['relateduserid']) ? $data['relateduserid'] : null;

        if (isset($event->context)) {
            if (isset($data['context'])) {
                debugging('Context was already set in init() method, ignoring context parameter', DEBUG_DEVELOPER);
            }

        } else if (!empty($data['context'])) {
            $event->context = $data['context'];

        } else if (!empty($data['contextid'])) {
            $event->context = \context::instance_by_id($data['contextid'], MUST_EXIST);

        } else {
            throw new \coding_exception('context (or contextid) is a required event property, system context may be hardcoded in init() method.');
        }

        $event->data['contextid'] = $event->context->id;
        $event->data['contextlevel'] = $event->context->contextlevel;
        $event->data['contextinstanceid'] = $event->context->instanceid;

        if (!isset($event->data['courseid'])) {
            if ($coursecontext = $event->context->get_course_context(false)) {
                $event->data['courseid'] = $coursecontext->instanceid;
            } else {
                $event->data['courseid'] = 0;
            }
        }

        if (!array_key_exists('relateduserid', $data) and $event->context->contextlevel == CONTEXT_USER) {
            $event->data['relateduserid'] = $event->context->instanceid;
        }

        // Warn developers if they do something wrong.
        if ($CFG->debugdeveloper) {
            static $automatickeys = array('eventname', 'component', 'action', 'target', 'contextlevel', 'contextinstanceid', 'timecreated');
            static $initkeys = array('crud', 'level', 'objecttable', 'edulevel');

            foreach ($data as $key => $ignored) {
                if ($key === 'context') {
                    continue;

                } else if (in_array($key, $automatickeys)) {
                    debugging("Data key '$key' is not allowed in \\core\\event\\base::create() method, it is set automatically", DEBUG_DEVELOPER);

                } else if (in_array($key, $initkeys)) {
                    debugging("Data key '$key' is not allowed in \\core\\event\\base::create() method, you need to set it in init() method", DEBUG_DEVELOPER);

                } else if (!in_array($key, self::$fields)) {
                    debugging("Data key '$key' does not exist in \\core\\event\\base");
                }
            }
        }

        // Let developers validate their custom data (such as $this->data['other'], contextlevel, etc.).
        $event->validate_data();

        return $event;
    }
 /**
  * Constructor
  *
  * @throws Exception if `default` group connection fails
  * @return void
  */
 public function __construct()
 {
     if (static::$init == FALSE) {
         // Register exception and error handler
         set_exception_handler(function ($e) {
             Gas::exception($e);
         });
         // Access current instance singleton
         $CI =& get_instance();
         // Load necessary configuration(s)
         $CI->config->load('gas', TRUE, TRUE);
         $CI->config->load('migration', TRUE, TRUE);
         // Set temporary config handler
         $config = array_merge($CI->config->item('gas'), array('migration' => $CI->config->item('migration')));
         // Validate DB instance
         if (!class_exists('CI_DB')) {
             $DB = $CI->load->database('default', TRUE);
             // Register into CI super object, so we could monitore it
             $CI->db = $DB;
         } else {
             $DB = $CI->db;
         }
         if ($config['auto_create_models'] == TRUE or $config['auto_create_tables'] == TRUE) {
             // Load necessary helper and library
             $CI->load->helper('file');
             $CI->load->library('migration');
         }
         // Include the bootstrap
         include_once APPPATH . 'third_party' . DIRECTORY_SEPARATOR . 'gas' . DIRECTORY_SEPARATOR . 'bootstrap.php';
         if (array_key_exists('auto', Gas\Core::$migration)) {
             // Execute migration if necessary
             if (!$CI->migration->latest()) {
                 show_error($CI->migration->error_string());
             }
         }
         // Set initialization flag
         static::$init = TRUE;
     }
 }
Exemple #20
0
 /**
  * Output the help based on the configuration of available
  * options and flags.
  *
  * @todo provide better option output and support arguments
  * if they are available. Currently, these are not set in init
  * but called directly from execute, so may need to refactor.
  */
 public static function help()
 {
     $output = array();
     // Only need to create an instance of the command, not passing
     // an InputResult since we are only getting info about the command.
     $instance = new static();
     // Call init so the flags and options will be set
     $instance->init();
     // Get the actual command by converting the class name
     $output[] = strtolower(str_replace('Command', '', get_class($instance)));
     // Show available flags
     if (!empty($instance->_flags)) {
         $output[] = '[-' . implode('', $instance->_flags) . ']';
     }
     // Show available options
     if (!empty($instance->_options)) {
         foreach ($instance->_options as $option => $config) {
             $option_help = '[-' . $option . ' option]';
             // required key is not explicitly set, if it doesn't exist it is required
             // required key must be explicitly set to FALSE for option to be optional
             if (!array_key_exists('required', $config) || $config['required'] === TRUE) {
                 $option_help .= '*';
             }
             $output[] = $option_help;
         }
     }
     return implode(' ', $output);
 }
Exemple #21
0
 /**
  * A static function that does the same as init()
  */
 public static function map($data)
 {
     $obj = new static();
     $obj->init($data);
     return $obj;
 }
Exemple #22
0
 /**
  * Initialize ORM
  *
  * Pass a config of the following format to the function:
  *   $config = [
  *       'driver'    => 'mysql', // Db driver
  *       'host'      => 'localhost',
  *       'database'  => 'my_database',
  *       'username'  => 'root',
  *       'password'  => 'root',
  *   ];
  *
  * @param config
  */
 public static function init($config)
 {
     new \Pixie\Connection('mysql', $config, 'DenBeke\\ORM\\DB');
     static::$init = true;
 }
Exemple #23
0
 /**
  * Get static information about an event.
  * This is used in reports and is not for general use.
  *
  * @return array Static information about the event.
  */
 public static final function get_static_info()
 {
     /** Var \core\event\base $event. */
     $event = new static();
     // Set static event data specific for child class.
     $event->init();
     return array('eventname' => $event->data['eventname'], 'component' => $event->data['component'], 'target' => $event->data['target'], 'action' => $event->data['action'], 'crud' => $event->data['crud'], 'edulevel' => $event->data['edulevel'], 'objecttable' => $event->data['objecttable']);
 }
Exemple #24
0
 /**
  * Maps data from the MongoDB database into an object instance
  */
 public static function map($data)
 {
     $obj = new static();
     if (isset($data['_id'])) {
         $obj->_id = $data['_id'];
         unset($data['_id']);
     }
     $obj->init($data);
     return $obj;
 }
Exemple #25
0
 /**
  * Implements ServiceProviderInterface::register() registering $app['crud'].
  * $app['crud'] contains an instance of the ServiceProvider afterwards.
  *
  * @param Container $app
  * the Container instance of the Silex application
  */
 public function register(Container $app)
 {
     $app['crud'] = function () use($app) {
         $result = new static();
         $fileProcessor = $app->offsetExists('crud.fileprocessor') ? $app['crud.fileprocessor'] : new SimpleFilesystemFileProcessor();
         $manageI18n = $app->offsetExists('crud.manageI18n') ? $app['crud.manageI18n'] : true;
         $result->init($app['crud.datafactory'], $app['crud.file'], $fileProcessor, $manageI18n, $app);
         return $result;
     };
 }
Exemple #26
0
 /**
  * Create new event.
  *
  * The optional data keys as:
  * 1/ objectid - the id of the object specified in class name
  * 2/ context - the context of this event
  * 3/ other - the other data describing the event, can not contain objects
  * 4/ relateduserid - the id of user which is somehow related to this event
  *
  * @param array $data
  * @return \core\event\base returns instance of new event
  *
  * @throws \coding_exception
  */
 public static final function create(array $data = null)
 {
     global $PAGE, $USER, $CFG;
     $data = (array) $data;
     /** @var \core\event\base $event */
     $event = new static();
     $event->triggered = false;
     $event->restored = false;
     $event->dispatched = false;
     // Set static event data specific for child class.
     $event->init();
     // Set automatic data.
     $event->data['timecreated'] = time();
     $classname = get_class($event);
     $parts = explode('\\', $classname);
     if (count($parts) !== 3 or $parts[1] !== 'event') {
         throw new \coding_exception("Invalid event class name '{$classname}', it must be defined in component\\event\\ namespace");
     }
     $event->data['eventname'] = '\\' . $classname;
     $event->data['component'] = $parts[0];
     $pos = strrpos($parts[2], '_');
     if ($pos === false) {
         throw new \coding_exception("Invalid event class name '{$classname}', there must be at least one underscore separating object and action words");
     }
     $event->data['target'] = substr($parts[2], 0, $pos);
     $event->data['action'] = substr($parts[2], $pos + 1);
     // Set optional data or use defaults.
     $event->data['objectid'] = isset($data['objectid']) ? $data['objectid'] : null;
     $event->data['courseid'] = isset($data['courseid']) ? $data['courseid'] : null;
     $event->data['userid'] = isset($data['userid']) ? $data['userid'] : $USER->id;
     $event->data['other'] = isset($data['other']) ? $data['other'] : null;
     $event->data['relateduserid'] = isset($data['relateduserid']) ? $data['relateduserid'] : null;
     if (isset($event->context)) {
         if (isset($data['context'])) {
             debugging('Context was already set in init() method, ignoring context parameter', DEBUG_DEVELOPER);
         }
     } else {
         if (!empty($data['context'])) {
             $event->context = $data['context'];
         } else {
             if (!empty($data['contextid'])) {
                 $event->context = \context::instance_by_id($data['contextid'], MUST_EXIST);
             } else {
                 throw new \coding_exception('context (or contextid) is a required event property, system context may be hardcoded in init() method.');
             }
         }
     }
     $event->data['contextid'] = $event->context->id;
     $event->data['contextlevel'] = $event->context->contextlevel;
     $event->data['contextinstanceid'] = $event->context->instanceid;
     if (!isset($event->data['courseid'])) {
         if ($coursecontext = $event->context->get_course_context(false)) {
             $event->data['courseid'] = $coursecontext->instanceid;
         } else {
             $event->data['courseid'] = 0;
         }
     }
     if (!array_key_exists('relateduserid', $data) and $event->context->contextlevel == CONTEXT_USER) {
         $event->data['relateduserid'] = $event->context->instanceid;
     }
     // Warn developers if they do something wrong.
     if ($CFG->debugdeveloper) {
         static $automatickeys = array('eventname', 'component', 'action', 'target', 'contextlevel', 'contextinstanceid', 'timecreated');
         static $initkeys = array('crud', 'level', 'objecttable');
         foreach ($data as $key => $ignored) {
             if ($key === 'context') {
                 continue;
             } else {
                 if (in_array($key, $automatickeys)) {
                     debugging("Data key '{$key}' is not allowed in \\core\\event\\base::create() method, it is set automatically", DEBUG_DEVELOPER);
                 } else {
                     if (in_array($key, $initkeys)) {
                         debugging("Data key '{$key}' is not allowed in \\core\\event\\base::create() method, you need to set it in init() method", DEBUG_DEVELOPER);
                     } else {
                         if (!in_array($key, self::$fields)) {
                             debugging("Data key '{$key}' does not exist in \\core\\event\\base");
                         }
                     }
                 }
             }
         }
     }
     // Let developers validate their custom data (such as $this->data['other'], contextlevel, etc.).
     $event->validate_data();
     return $event;
 }
Exemple #27
0
 public function createTask(BuildInterface $build = null)
 {
     $new = new static($this->getPlugin());
     $new->init($build);
     return $new;
 }
 public static function getInstance()
 {
     $model = new static();
     $model->init(self::getAdapterInstance(), new TableGateway($model->table, self::getAdapterInstance()), new Sql(self::getAdapterInstance()));
     return $model;
 }
Exemple #29
0
 /**
  * Return an instance of the Core_Daemon singleton
  * @return Core_Daemon
  */
 public static function getInstance()
 {
     static $o = null;
     if (!$o) {
         try {
             $o = new static();
             $o->setup_plugins();
             $o->setup_workers();
             $o->check_environment();
             $o->init();
         } catch (Exception $e) {
             $o->fatal_error($e->getMessage());
         }
     }
     return $o;
 }