我不熟悉Symfony,在尝试执行cron作业时遇到问题。我真的很笨,这是怎么了。似乎我正在尝试从全局名称空间访问handleChange(event){
if(event.target.checked) {
this.setState({
filters: [...filters, event.target.name]
});
}
else {
let array = [...filters];
if(array.include(e.target.name)) {
array.splice(indexOf(e.target.name);
this.setState({filters: array)})
}
}
}
中存在的某些函数,但是我无法弄清楚它是哪个名称空间。以下是我的代码。
app/config/functions.php
运行时发生错误,<?php
namespace App\Command;
use App\Services\Upcontent\Upcontent;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class UpcontentRefreshCommand extends Command
{
protected static $defaultName = 'app:upcontent-refresh';
private $upcontent;
public function __construct(Upcontent $upcontent)
{
$this->upcontent = $upcontent;
parent::__construct();
}
protected function configure()
{
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln([
'',
'=================',
'Upcontent Refresh',
'=================',
'',
]);
$output->writeln('Clearing Cache...');
clear_cache();
$output->writeln('Cache Cleared');
$output->writeln('Refreshing Sports Topic...');
$output->writeln('Loading, be patient...');
$sports = $this->upcontent->getTopic('########');
$output->writeln([
'',
'=====================',
'End Upcontent Refresh',
'=====================',
'',
]);
}
}
?>
,请帮忙。提前致谢。
答案 0 :(得分:1)
您可能必须更新“自动加载”部分,以确保已加载自定义的function.php。
{
"autoload": {
"psr-4" {
"App\\": "src/"
},
"files": ["app/config/functions.php"]
}
}
您可能还想重构该文件,以将功能移到某种服务类中,例如像这样:
# src/Yaml/Parser.php
<?php
namespace App\Yaml;
class Parser
{
public function parseFile(string $fileName)
{
// The logic from your yaml_parse_file() inside your functions.php
}
}
然后在您的命令中(或您需要自定义yaml解析的任何地方)注入服务:
use App\Yaml\Parser;
class MyService
{
private $yamlParser;
public function __construct(Parser $yamlParser)
{
$this->yamlParser = $yamlParser;
}
// ...
public function something()
{
$this->yamlParser->parseFile($filename);
}
}
由于Symfony提供了Yaml组件,因此您甚至可能想要使用它。