dongxie3352 2017-03-14 01:53
浏览 35
已采纳

使用symfony2控制器的外部库

I would like to use php library in symfony2 Command. http://phpmidiparser.com/quickstart

I put the library on the same folder of symfony2 but in vain.

Command/Midi/bootstrap.php
Command/myCommand.php
$ php app/console top:myCommand

syntax error, unexpected 'use' (T_USE) in error at use \Midi\Parsing\FileParser;

require_once 'Midi/bootstrap.php';

use \Midi\Parsing\FileParser;
use \Midi\Reporting\TextFormatter;
use \Midi\Reporting\Printer;

$parser = new FileParser();
$parser->load('/path/to/midi/file.mid');

$printer = new Printer(new TextFormatter(), $parser);
$printer->printAll();

I use this library only in Command ,so I don't need to register this on autoload.

Please teach me basic guideline of using external library, where should I put the library and how can I 'require'?

  • 写回答

1条回答 默认 最新

  • dousong8187 2017-03-14 02:23
    关注

    usekeyword must appear before require_once (http://php.net/manual/en/language.namespaces.importing.php)

    use \Midi\Parsing\FileParser;
    use \Midi\Reporting\TextFormatter;
    use \Midi\Reporting\Printer;
    
    require_once 'Midi/bootstrap.php';
    
    $parser = new FileParser();
    $parser->load('/path/to/midi/file.mid');
    
    $printer = new Printer(new TextFormatter(), $parser);
    $printer->printAll();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部