我的symfony应用程序中有Service目录,如下所示
的src / SwipeBundle /服务
在这个目录中,我有一个名为。
的类RSA.php
这个班有
namespace SwipeBundle\Service;
require_once __DIR__ . 'RSA/Crypt/RSA.php';
require_once __DIR__ . 'RSA/File/X509.php';
class RSA
{
public function privateKey() {
require_once __DIR__ . 'RSA/Certificates/private.txt';
}
public function certificates() {
return require_once __DIR__ . 'RSA/Certificates/pinew.cer';
}
}
,文件目录为
的src / SwipeBundle /服务/ RSA /认证/ pinew.cer SRC / SwipeBundle /服务/ RSA /证书/ private.txt SRC / SwipeBundle /服务/ RSA /隐窝/ RSA.php
的src / SwipeBundle /服务/ RSA /文件/ X509.php
我想将这个服务类的类加载到我的Controller中,就像这样。
控制器
use SwipeBundle\Service;
class BillsPayController extends Controller
{
public function indexAction() {
$rsa = new \Crypt_RSA();
$hash = new \Crypt_Hash('sha1');
$x509 = new \File_X509();
$privatekey = file_get_contents(RSA()->privateKey());
$x509->loadX509(file_get_contents(RSA()->certificates()));
}
}
I tried also using this one.
use SwipeBundle\Service\RSA;
class BillsPayController extends Controller
{
public function indexAction() {
$a = new RSA();
$a->privateKey();
}
}
我遇到错误。
Attempt result 1: Attempted to load class "Crypt_RSA" from the global namespace.
Did you forget a "use" statement?
Attempt result 2: Compile Error: main(): Failed opening required '/Users/jaysonlacson/Sites/contactless/src/SwipeBundle/ServiceRSA/Crypt/RSA.php' (include_path='.:')
答案 0 :(得分:0)
我认为你错过了这样的正斜杠:
require_once __DIR__ . '/RSA/Crypt/RSA.php';
require_once __DIR__ . '/RSA/File/X509.php';
我只是猜测,但你可以试试吗?