May be a very bad question. Not sure.
Just a brief
I am trying to add simplesamlphp in magento2.
1) I added it through composer and its added inside vendor directory. And i can access the classes like this
$auth = new \SimpleSAML_Auth_Simple('default-sp');And this works..and i can access functions also.
Now the issue is its not written keeping magento2's structure in mind. It will work only if i put the whole code in magento2's root.
EDIT
Now if i put the whole code in magento root and try to access like this(dont get me wrong..just try to check with object manager. Wont use it. Chill.)
$object_manager = \Magento\Framework\App\ObjectManager::getInstance();
 $dir = $object_manager->get('\Magento\Framework\Filesystem\DirectoryList'); 
 $base = $dir->getRoot();
 $lib_file = $base.'/simplesamlphp/simplesamlphp/lib/_autoload.php';
 require_once($lib_file);
 $auth = new SimpleSAML_Auth_Simple('default-sp');
It gives me this
Fatal error: Class 'Magento\Customer\Controller\Account\SimpleSAML_Auth_Simple' not found. // BTW trying to call it from
LoginPostaction.
How to include classes which are at magento2's root? (Probably autoload wont work but still)
1 Answer 1
Try with backslash before
$auth = new \SimpleSAML_Auth_Simple('default-sp');
 ^
Multiple namespaces may also be declared in the same file. There are simple and bracketed allowed syntaxes.
Simple combination syntax
<?php namespace MyProject; const CONNECT_OK = 1; class Connection { /* ... */ } function connect() { /* ... */ } namespace AnotherProject; const CONNECT_OK = 1; class Connection { /* ... */ } function connect() { /* ... */ }This syntax is not recommended for combining namespaces into a single file. Instead it is recommended to use the alternate bracketed syntax.
Bracketed syntax
<?php namespace MyProject { const CONNECT_OK = 1; class Connection { /* ... */ } function connect() { /* ... */ } } namespace AnotherProject { const CONNECT_OK = 1; class Connection { /* ... */ } function connect() { /* ... */ } }It is strongly discouraged as a coding practice to combine multiple namespaces into the same file. The primary use case is to combine multiple PHP scripts into the same file.
To combine global non-namespaced code with namespaced code, only bracketed syntax is supported. Global code should be encased in a namespace statement with no namespace name as in:
Unnamespaced code
<?php namespace MyProject { const CONNECT_OK = 1; class Connection { /* ... */ } function connect() { /* ... */ } } namespace { // global code session_start(); $a = MyProject\connect(); echo MyProject\Connection::start(); }No PHP code may exist outside of the namespace brackets except for an opening declare statement.
src: http://php.net/manual/en/language.namespaces.definitionmultiple.php
- 
 Probably you didnt read my post properly. I already tried that. That only works when you have it inside vendor folder.Kingshuk Deb– Kingshuk Deb2017年11月15日 18:59:07 +00:00Commented Nov 15, 2017 at 18:59
- 
 Put the code in magento root, it's a bad practicesNolwennig– Nolwennig2017年11月17日 12:01:15 +00:00Commented Nov 17, 2017 at 12:01
- 
 Declare multiple namespaces?Nolwennig– Nolwennig2017年11月17日 12:11:27 +00:00Commented Nov 17, 2017 at 12:11