Differences

This shows you the differences between two versions of the page.

Link to this comparison view

dev:apibasics [2011/04/12 23:29] (current)
gradator created
Line 1: Line 1:
 +====== API : the basics ======
  
 +
 +===== VHFFS subsystem : init =====
 +To initialize VHFFS subsystem, you have to create an instance of //​Vhffs::​Main//​ module. If VHFFS is well-done configured (''/​etc/​vhffs/​vhffs.conf''​ is good), the backend is created and runs, it will just works ! To initialize the VHFFS subsystem, just type this code : 
 +
 +''#​!/​usr/​bin/​perl''​
 +
 +''​use Vhffs::​Main;''​
 +
 +''​my $vhffs = init Vhffs::​Main;''​
 +
 +''​if( defined $vhffs ){''​
 +
 +'' ​   print "VHFFS subsystem is now initialized";''​
 +
 +''​}else{''​
 +
 +''​print "VHFFS initialization error";''​
 +
 +''​}''​
 +
 +
 +Don't forget the //​Vhffs::​Main//​ instance, it will be used for ALL modules and is the center of VHFFS-API. You can't do many things without it (in other words : you cannot do something without it).
 +
 +When you involve ''​$vhffs = init Vhffs::​Main;'',​ then :
 +  - The main config-file is read
 +  - Connexions to the backend are established
 +  - A ''​Vhffs::​Conf''​ is created and encapsulated in the returned ''​Vhffs::​Main''​ object.
 +
 +
 +
 +===== The getall method =====
 +A particular method in VHFFS API is the ''​getall''​ method. Implemented on all modules, it's more easy to get objects with it. With the ''​getall''​ method, you can : 
 +  - Search for an object that belong to a group
 +  - Search for an object that have a name like something
 +  - Search for an object that belong to a specific user
 +  - Search for object that have a specific status
 +  - ...
 +
 +For example, the getall method can returns all websites objects (''​Vhffs::​Services::​Httpd module''​) that belong to the group //​mygroup//,​ are activated and are call like ''​mywebsite.com''​.
 +
 +The typical ''​getall''​ definition is :
 +
 +''​getall( $vhffs , $state , $name , $group )''​ with the following arguments :
 +  - ''​$vhffs''​ is a ''​Vhffs::​Main''​ object. You must create it with an ''​$vhffs = init Vhffs::​Main''​ call.
 +  - ''​$state''​ is a number with symbolized a state of VHFFS. States are stored in the ''​Vhffs::​Constants''​ module. You can use ''​$state''​ as ''​Vhffs::​Constants::​ACTIVATED''​.
 +  - ''​$name''​ is the name of the service you search. It's not the exact name, and all services that matches ''​$name''​ will be returned.
 +  - ''​$group''​ is the group that own the searched service. Must be a ''​Vhffs::​Group''​ reference.
 +
 +
 +===== The commit() method =====
 +
 +Each object implements a ''​commit()''​ method. Purpose of this method is to save all changes made on objects. For example, if you fetch an object from VHFFS database and you modify some informations on this object. To save changes, you have to invoke the ''​commit()''​ method on the object.
 +
 +Example : ''​$object->​commit''​
 +
 +This method will return a negative value if fails.
 + 
 +
 +
 +
 +===== The fetch() method =====
 +<​del>​When you have an object, you can fetch informations about it in the database. For example, you have a ''​Vhffs::​User''​ with username //Kevin//. If you want get all informations in the database about this user, you have to invoke the ''​fetch()''​ method on the object.</​del>​
 +
 +<​del>​The method will return a negative value if fails. This is very important, because you can test if an object already exists in the database : you create the object, and when invoking ''​fetch()''​ method, if it returns a negative value, the object does not exists in the database. Else, it already exists and cannot be created.
 +</​del>​
 +
 +This method will be deprecated in VHFFS 4.1 since you have to create a ''​new''​ object with dummy data before calling it. Instead, use directly ''​Vhffs::​Xxxx::​get_by_yyyy($vhffs,​ $value)''​ method wich return a fully functional object with all its data filled (''​Xxxxx''​ is the classname, '​yyyy'​ the criteria wich must match ''​$value''​).
 +
 +''​Fetch''​ has been tagged as deprecated, a warning is printed for each call to it.
 +
 +===== The create() method =====
 +The ''​create()''​ method will store an object in the database. If fail, returns negative value.
 +
 +====== Packages ======
 +===== Vhffs::Xxxx ======
 +This package contains heavy weight objects. You should only use its facilities when you need to modify, create or delete an object.
 +===== Vhffs::​Panel::​Xxxx =====
 +This package contains methods wich returns hashes with data about objects. The hashes doesn'​t have any method to modify the object. Use it when you need lightweight objects, e.g. for display.
 +===== Vhffs::​Robots::​Xxxx =====
 +This package is used by Robots, it could be removed soon
Recent changes RSS feed Creative Commons License Donate Minima Template by Wikidesign Driven by DokuWiki