/** * Instantiates built-in cache by name * @param string $cache * @return false|epCache * @throws epExceptionCacheObject */ protected function &_getCache($name = 'apc') { // normalize cache name $name = strtolower($name); // check if it is one of the built-in caches if (!in_array($name, array_keys(self::$builtin_caches))) { throw new epExceptionCacheObject("Unrecognized built-in cache: {$cache}"); return false; } // collect all arguments for cache constructor $args = array(); foreach (self::$builtin_caches[$name] as $option) { $args[] = $this->getConfigOption($option); } // class name for the built-in cache $class = epCache . ucfirst($name); // include the class source file include_once EP_SRC_CACHE . '/' . $class . '.php'; // instantiate it return epNewObject($class, $args); }
/** * Create the foreign object with a given array of arguments * @param string $foreign_class name of the foreign class * @param arrary $args arguments for object creatatoin * @return bool * @access private */ protected function &newForeignObject($foreign_class, $args) { $this->foreign_object =& epNewObject($foreign_class, $args); return !is_null($this->foreign_object); }
/** * Low level create (called by {@link create()}) * Create a new instance of a class * * Although this method is made public for {@link epDbObject} to be able * to call in assembling objects from database rows, it is <b>not</b> * recommended to be used. Please use {@epManager::create()} instead. * * @param string|object $class_or_obj class name or an object * @param boolean $caching whether to cache the newly created object * @param boolean $dispatch_event whether to dispatch event * @return null|epObject * @access public * @throws epExceptionManagerBase */ public function &_create($class_or_obj, $caching = true, $dispatch_event = true, $args = array()) { // check if the argument is a string (class name) $class = ''; $o = false; if (is_string($class_or_obj)) { $class = $class_or_obj; } else { if (is_object($class_or_obj)) { $o =& $class_or_obj; $class = get_class($o); } else { throw new epExceptionManagerBase('Argument unrecognized. It should be either object or class name (string)'); return self::$null; } } // check if class has been compiled if (!($cm =& $this->_getMap($class))) { // if not, check if auto_compile is enabled if (!$this->getConfigOption('auto_compile')) { // if not (auto_compile off), throw throw new epExceptionManagerBase('Class ' . $class . ' has not been compiled. ' . 'It cannot be made persistable. Either enable ' . 'auto_compile or compile manually'); return self::$null; } // otherwise (auto compile enabled) if (!($cm =& $this->_compileClass($class))) { // return false if auto-compile fails return self::$null; } } // event: onPreCreate if ($dispatch_event) { $this->_dispatchEvent(array('onPreCreate'), $class, $args); } // in case the argument is not object, create it if (!$o) { // make a new instance if (!($o =& epNewObject($class, $args))) { // throw if failed to create an object throw new epExceptionManagerBase('Cannot create object for class [' . $class . ']'); return self::$null; } } // wrap object if it doesn't have epObject ifc if (!$o instanceof epObject) { if (!($o = new epObject($o, $cm))) { throw new epExceptionManagerBase('Cannot wrap object of [' . $class . ']'); return self::$null; } } // cache it in the array of uncommited objects (only when auto_flush is on) if ($caching) { $this->objects_uc[$o->epGetUId()] =& $o; } // event: onCreate, onPostCreate if ($dispatch_event) { $this->_dispatchEvent(array('onCreate', 'onPostCreate'), $o); } return $o; }