__construct() public method

Plugin developers should only use the constructor to create a new entity. To retrieve entities, use get_entity() and the elgg_get_entities* functions. If no arguments are passed, it creates a new entity. If a database result is passed as a \stdClass instance, it instantiates that entity.
public __construct ( stdClass $row = null )
$row stdClass Database row result. Default is null to create a new object.
Beispiel #1
0
 /**
  * Construct hjFrom
  */
 function __construct($guid = null)
 {
     parent::__construct($guid);
     if (!$guid) {
         $this->setDefaults();
     }
 }
Beispiel #2
0
 /**
  * Loads the plugin by GUID or path.
  *
  * @warning Unlike other ElggEntity objects, you cannot null instantiate
  *          ElggPlugin. You must point it to an actual plugin GUID or location.
  *
  * @param mixed $plugin The GUID of the ElggPlugin object or the path of
  *                      the plugin to load.
  */
 public function __construct($plugin)
 {
     if (!$plugin) {
         throw new PluginException(elgg_echo('PluginException:NullInstantiated'));
     }
     // ElggEntity can be instantiated with a guid or an object.
     // @todo plugins w/id 12345
     if (is_numeric($plugin) || is_object($plugin)) {
         parent::__construct($plugin);
         $this->path = elgg_get_plugins_path() . $this->getID();
     } else {
         $plugin_path = elgg_get_plugins_path();
         // not a full path, so assume an id
         // use the default path
         if (strpos($plugin, $plugin_path) !== 0) {
             $plugin = $plugin_path . $plugin;
         }
         // path checking is done in the package
         $plugin = sanitise_filepath($plugin);
         $this->path = $plugin;
         $path_parts = explode('/', rtrim($plugin, '/'));
         $plugin_id = array_pop($path_parts);
         $this->pluginID = $plugin_id;
         // check if we're loading an existing plugin
         $existing_plugin = elgg_get_plugin_from_id($this->pluginID);
         $existing_guid = null;
         if ($existing_plugin) {
             $existing_guid = $existing_plugin->guid;
         }
         // load the rest of the plugin
         parent::__construct($existing_guid);
     }
 }
Beispiel #3
0
 /**
  * Creates a new plugin from path
  *
  * @note Internal: also supports database objects
  *
  * @warning Unlike other \ElggEntity objects, you cannot null instantiate
  *          \ElggPlugin. You must provide the path to the plugin directory.
  *
  * @param string $path The absolute path of the plugin
  *
  * @throws PluginException
  */
 public function __construct($path)
 {
     if (!$path) {
         throw new \PluginException("ElggPlugin cannot be null instantiated. You must pass a full path.");
     }
     if (is_object($path)) {
         // database object
         parent::__construct($path);
         $this->path = _elgg_services()->config->getPluginsPath() . $this->getID();
         _elgg_cache_plugin_by_id($this);
         return;
     }
     if (is_numeric($path)) {
         // guid
         // @todo plugins with directory names of '12345'
         throw new \InvalidArgumentException('$path cannot be a GUID');
     }
     $this->initializeAttributes();
     // path checking is done in the package
     $path = sanitise_filepath($path);
     $this->path = $path;
     $path_parts = explode('/', rtrim($path, '/'));
     $plugin_id = array_pop($path_parts);
     $this->title = $plugin_id;
     // check if we're loading an existing plugin
     $existing_plugin = elgg_get_plugin_from_id($plugin_id);
     if ($existing_plugin) {
         $this->load($existing_plugin->guid);
     }
     _elgg_cache_plugin_by_id($this);
 }
Beispiel #4
0
 public function __construct($guid = null)
 {
     if ($guid && !is_object($guid)) {
         // Loading entities via __construct(GUID) is deprecated, so we give it the entity row and the
         // attribute loader will finish the job. This is necessary due to not using a custom
         // subtype (see above).
         $guid = get_entity_as_row($guid);
     }
     parent::__construct($guid);
 }
 /**
  * Class constructor
  *
  * @param integer  $guid The object guid
  * @param integer  $user_guid The users guid
  * @param string   $description The description (reason) for these points
  */
 public function __construct($guid = null, $user_guid = null, $description = null)
 {
     parent::__construct($guid);
     if ($guid) {
         return true;
     }
     if (!($user = get_entity($user_guid))) {
         return false;
     }
     $this->attributes['owner_guid'] = $user_guid;
     $this->attributes['container_guid'] = $user_guid;
     $this->attributes['description'] = $description;
 }
Beispiel #6
0
 /**
  * Loads the plugin by GUID or path.
  *
  * @warning Unlike other ElggEntity objects, you cannot null instantiate
  *          ElggPlugin. You must point it to an actual plugin GUID or location.
  *
  * @param mixed $plugin The GUID of the ElggPlugin object or the path of
  *                      the plugin to load.
  */
 public function __construct($plugin)
 {
     if (!$plugin) {
         throw new PluginException(elgg_echo('PluginException:NullInstantiated'));
     }
     // ElggEntity can be instantiated with a guid or an object.
     // @todo plugins w/id 12345
     if (is_numeric($plugin) || is_object($plugin)) {
         parent::__construct($plugin);
         $this->path = elgg_get_plugins_path() . $this->getID();
     } else {
         $plugin_path = elgg_get_plugins_path();
         // not a full path, so assume an id
         // use the default path
         if (strpos($plugin, $plugin_path) !== 0) {
             $plugin = $plugin_path . $plugin;
         }
         // path checking is done in the package
         $plugin = sanitise_filepath($plugin);
         $this->path = $plugin;
         $path_parts = explode('/', rtrim($plugin, '/'));
         $plugin_id = array_pop($path_parts);
         $this->pluginID = $plugin_id;
         // check if we're loading an existing plugin
         $existing_plugin = elgg_get_plugin_from_id($this->pluginID);
         $existing_guid = null;
         if ($existing_plugin) {
             $existing_guid = $existing_plugin->guid;
         }
         // load the rest of the plugin
         parent::__construct($existing_guid);
     }
     // We have to let the entity load so we can manipulate it with the API.
     // If the path is wrong or would cause an exception, catch it,
     // disable the plugin, and emit an error.
     try {
         $this->package = new ElggPluginPackage($this->path, false);
         $this->manifest = $this->package->getManifest();
     } catch (Exception $e) {
         // we always have to allow the entity to load.
         elgg_log("Failed to load {$this->guid} as a plugin. " . $e->getMessage(), 'WARNING');
         $this->errorMsg = $e->getmessage();
     }
 }
Beispiel #7
0
 /**
  * Creates a new plugin from path
  *
  * @internal also supports database objects
  *
  * @warning Unlike other ElggEntity objects, you cannot null instantiate
  *          ElggPlugin. You must provide the path to the plugin directory.
  *
  * @param string $path The absolute path of the plugin
  *
  * @throws PluginException
  */
 public function __construct($path)
 {
     if (!$path) {
         throw new PluginException("ElggPlugin cannot be null instantiated. You must pass a full path.");
     }
     if (is_object($path)) {
         // database object
         parent::__construct($path);
         $this->path = elgg_get_plugins_path() . $this->getID();
     } else {
         if (is_numeric($path)) {
             // guid
             // @todo plugins with directory names of '12345'
             elgg_deprecated_notice("Use elgg_get_plugin_from_id() to load a plugin.", 1.9);
             parent::__construct($path);
             $this->path = elgg_get_plugins_path() . $this->getID();
         } else {
             $mod_dir = elgg_get_plugins_path();
             // not a full path, so assume a directory name and use the default path
             if (strpos($path, $mod_dir) !== 0) {
                 elgg_deprecated_notice("You should pass a full path to ElggPlugin.", 1.9);
                 $path = $mod_dir . $path;
             }
             // path checking is done in the package
             $path = sanitise_filepath($path);
             $this->path = $path;
             $path_parts = explode('/', rtrim($path, '/'));
             $plugin_id = array_pop($path_parts);
             $this->pluginID = $plugin_id;
             // check if we're loading an existing plugin
             $existing_plugin = elgg_get_plugin_from_id($this->pluginID);
             $existing_guid = null;
             if ($existing_plugin) {
                 $existing_guid = $existing_plugin->guid;
             }
             // load the rest of the plugin
             parent::__construct($existing_guid);
         }
     }
     _elgg_cache_plugin_by_id($this);
 }
 public function __construct($guid = null)
 {
     parent::__construct($guid);
 }
Beispiel #9
0
 /**
  * Loads an \ElggFile entity.
  *
  * @param \stdClass $row Database result or null for new \ElggFile
  */
 public function __construct($row = null)
 {
     parent::__construct($row);
     // Set default filestore
     $this->filestore = $this->getFilestore();
 }
Beispiel #10
0
 function __construct()
 {
     parent::__construct();
 }