From da7779dc1d7962e25f8f5e7142428a6879fb2d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Sauvat?= Date: Fri, 28 Aug 2015 16:27:31 +0200 Subject: [PATCH] Update README.md to match latests API changes. --- README.md | 77 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 3b34fe8..7243e29 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,61 @@ # inetprocess/sugarcrm -That library allows anybody to interact with a SugarCRM application, outside that application. Suppose you need to do a importation script, running every night, with a very specific set of transformations or check. Then you need that kind of tools to be able to "Login" to SugarCRM, create or update beans, do SQL queries, etc ... +That library allows anybody to interact with a SugarCRM application, outside that application. +Suppose you need to do a importation script, running every night, with a very specific set of +transformations or check. Then you need that kind of tools to be able to "Login" to SugarCRM, +create or update beans, do SQL queries, etc ... # Warning -* Be very careful that Sugar doesn't do a very "clean" job so it's better to deactivate the strict standards erorr reporting in PHP to be able to use it. When I launch my script, I usualy do something like: +* Be very careful that Sugar doesn't do a very "clean" job so it's better to deactivate +the strict standards erorr reporting in PHP to be able to use it. When I launch my script, I usualy do something like: ```bash php -d 'error_reporting=E_ALL & ~E_STRICT' test.php ``` -* If you are not using my classes in another class (if you do like in examples below, directly calling the library), be more careful: **don't name your variables like sugar does, else you'll overwrite it** (example: _$db_ or _$log_). +* If you are not using my classes in another class (if you do like in examples below, directly calling the library), +be more careful: **don't name your variables like sugar does, else you'll overwrite it** (example: _$db_ or _$log_). -* Last but not the least: you'll be able to instanciate the EntryPoint for only one instance of Sugar ! It uses GLOBALS variable such as $GLOBALS['db'] and I let you imagine what will happen if it's overwritten by another Instance of SugarCRM ;) +* Last but not the least: you'll be able to instanciate the EntryPoint for only one instance of Sugar ! +It uses GLOBALS variable such as $GLOBALS['db'] and I let you imagine what will happen +if it's overwritten by another Instance of SugarCRM ;) # Classes -## Inet\SugarCRM\EntryPoint -That's the class all other classes need. It says where is Sugar and does the basic steps to "login" into SugarCRM. EntryPoint needs a logger because other classes log a lot of stuff. +## Inet\SugarCRM\Application +Gives general information about SugarCRM Installation. +Others classes depends on this one. Usage Example: ```php getSugarPath(); +if ($sugarApp->isValid()) { + echo $sugarApp->getVersion(); +} ``` -## Inet\SugarCRM\Application -Gives general information about SugarCRM Installation. For now, it only gives the same path we set on $entryPoint. +## Inet\SugarCRM\EntryPoint +It says where is Sugar and does the basic steps to "login" into SugarCRM. +EntryPoint needs a logger because other classes log a lot of stuff. +The EntryPoint can only be loaded once for the entire program. Usage Example: ```php getSugarPath(); +if (!EntryPoint::isCreated()) { + $nullLogger = new NullLogger; + $sugarApp = new Application('/home/sugarcrm/www'); + // enter sugar + EntryPoint::createInstance($nullLogger, $sugarApp, '1'); +} +$sugarEP = EntryPoint::getInstance(); ``` ## Inet\SugarCRM\Bean @@ -62,14 +75,18 @@ use Inet\SugarCRM\EntryPoint; use Inet\SugarCRM\DB; use Inet\SugarCRM\Bean; -$nullLogger = new NullLogger; -// enter sugar -$sugarInetEP = new EntryPoint($logger, '/home/sugarcrm/www', '1'); +if (!EntryPoint::isCreated()) { + $nullLogger = new NullLogger; + $sugarApp = new Application('/home/sugarcrm/www'); + // enter sugar + EntryPoint::createInstance($nullLogger, $sugarApp, '1'); +} +$sugarEP = EntryPoint::getInstance(); // get the DB Class -$inetSugarDB = new DB($sugarInetEP); +$inetSugarDB = new DB($sugarEP); // instanciate the Bean class to retrieve User with id 1 -$inetSugarBean = new Bean($sugarInetEP, $inetSugarDB); +$inetSugarBean = new Bean($sugarEP, $inetSugarDB); $adminUser = $inetSugarBean->getBean('Users', 1); echo $adminUser->name; ``` @@ -84,15 +101,11 @@ Usage Example: ```php doQuery('SELECT * FROM users'); echo count($users); ``` @@ -104,15 +117,11 @@ Usage Example: ```php arrayToMultiselect(array('test' => 'inet')); echo $convertedArray;