I'm trying to include the PHPInsight library for performing sentiment analysis on user data.
Based on the demo file provided in it, I added it into the sites/all/libraries
path so that it would read sites/all/libraries/phpInsight
and tried to create an object
$sentiment = new \PHPInsight\Sentiment();
which resulted in blank screen.
Following this I looked into
- Include a third party library using namespaces, dependencies and
- https://www.drupal.org/node/1976234.
Apparently owing to a known constraint of D7 with namespace installed the xautoload and modified the hook_libraries_info
as below
function analyzer_libraries_info() {
$libraries['phpInsight'] = array(
'name' => 'PHP Insight',
'vendor url' => 'https://github.com/JWHennessey/phpInsight',
'download url' => 'https://github.com/JWHennessey/phpInsight/archive/master.zip',
'files' => array(
'php' => array('autoload.php'),
),
'xautoload' => function($adapter) {
$adapter->namespaceRoot('\PHPInsight', 'lib');
},
);
return $libraries;
}
I'm still uncertain about how to use the xautoload and my autoload file that needs to be included is in sites/all/libraries/phpInsight/autoload.php
. Since I haven't used libraries API or PHP namespaces and some clarity on what needs to be done to get it included and instantiate the object with how it happens would be of great help.
$adapter->namespaceRoot('\PHPInsight', 'lib');
would be$adapter->namespaceRoot('\PHPInsight', 'sites/all/libraries/phpInsight');
or similar?'lib'
would probably only make sense if the library code was at analyzer/lib/PHPInsight. You might want to change the library folder to be case sensitive too to match the library name (PHPInsight
), that usually makes a difference with PSR-0 autoloaders IIRC – Clive♦ May 28 '15 at 14:28$adapter->namespaceRoot('\PHPInsight', 'PHPInsight');
, with the folder renamed to match the case – Clive♦ May 28 '15 at 14:31$adapter->namespaceRoot('PHPInsight', 'lib');
So without the backslash in the beginning. – donquixote May 28 '15 at 20:55$adapter->add('PHPInsight', 'lib');
, which is the Composer syntax for PSR-0, I think to remember. – donquixote May 28 '15 at 20:56