-1

考えられるすべての回答を確認しましたが、申し訳ありませんが、これを理解できませんでした。プロパティを非静的にしようとしましたが、コードパッドは次の行にエラーを表示します:

$task = new sfCacheClearTask($sfContext::getInstance()->getEventDispatcher(), new sfFormatter());

http://codepad.org/zcqrkVoYを参照してください

これを解決するのを手伝ってください。ありがとう

class doSokiJobTask extends sfBaseTask {

    CONST STATUS_PENDING = 0;
    CONST STATUS_DONE = 1;
    CONST STATUS_IN_PROGRESS = 2;
    CONST STATUS_FAILED = 3;
    CONST STATUS_CANCELLED = 4;

    CONST TIME_TO_DIE = 60;

    public $context = null;
    public $job_name = null;
    public $done = null;
    public $status = null;
    public $start = 0;

    protected function setJobName($name) {
        $this->job_name = strtolower($name);
    }

    protected function configure() {
        $this->addArguments(array(
                //new sfCommandArgument('build', sfCommandArgument::REQUIRED, ''),
        ));

        $this->addOptions(array(
            new sfCommandOption('env', null, sfCommandOption::PARAMETER_OPTIONAL, 'Env to use', 'dev'),
            new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'Env to use', 'frontend'),
            new sfCommandOption('job-type', null, sfCommandOption::PARAMETER_REQUIRED, 'Job to be executed', 'job'),
            new sfCommandOption('daemon', null, sfCommandOption::PARAMETER_REQUIRED, 'Daemon running the job', 0),
        ));

        $this->namespace = 'soki';
        $this->name = 'job';
        $this->briefDescription = 'Lets you run jobs in the background';
        $this->detailedDescription = <<<EOF
The [setup|INFO] task helps run jobs in the background.
Call it with:

  [php symfony setup|INFO]
EOF;
//$this->filesystem = new sfFilesystem(null, $this->formatter);
    }

    protected function execute($arguments = array(), $options = array()) {
        $this->start = $ts_start = microtime(true);
        $options['quiet'] = 'true';
        $configuration = ProjectConfiguration::getApplicationConfiguration($options['application'], $options['env'], true);
        new sfDatabaseManager($configuration);
        $sfContext = sfContext::createInstance($configuration);
        $this->context = $sfContext;
        $this->setJobName($options['job-type']);
        if (true) {
            $file_logger = new sfFileLogger($this->dispatcher, array('file' => $this->configuration->getRootDir() . '/log/jobs.log'));
            $this->dispatcher->connect('command.log', array($file_logger, 'listenToLogEvent'));
        }

        try {
            if (!$this->job_name)
                $this->logSection('INVALID', 'Job Type could not be identified', null, 'ERROR');

            switch ($this->job_name) {
                case 'clear-cache':
                    $task = new sfCacheClearTask($sfContext::getInstance()->getEventDispatcher(), new sfFormatter());
                    $task->run(array(), array('env' => $options['env'], 'app' => $options['application']));
                    $this->done = true;
                    break;
                case 'send-email':
                    $task = new sfProjectSendEmailsTask($sfContext::getInstance()->getEventDispatcher(), new sfFormatter());
                    $task->run(array(), array('env' => $options['env'], 'application' => $options['application'],
                        'message-limit' => sfConfig::get('sf_spool_message_limit', 25)));
                    $this->done = true;
                    break;
                case 'chmod':
                    if (!chmod(sfConfig::get('sf_root_dir') . "/data_society", 0755))
                        throw new Exception('CHMOD failed on ' . sfConfig::get('sf_root_dir') . "/data_society");
                    $this->done = true;
                    break;
                case 'disable-install':
                    $this->done = Application::secureSokiInstaller(true);
                    sokiUtil::clearCacheAsync();
                    break;
                /* case 'enable-install':
                  Application::secureSokiInstaller(false);
                  sokiUtil::clearCacheAsync();
                  break; */
                case 'job':
                    $this->executeJob($arguments, $options);
                    break;
                default:
                    $this->logSection('UNKNOWN', 'Job Type could not be identified', null, 'ERROR');
                    break;
            }
            $ts_end = microtime(true);
            $this->logSection($this->job_name, ($this->done ? 'DONE' : 'FAILED') . ' in ' . round($ts_end - $ts_start) . 's @ ' . $options['env'] . '/' . $options['application'], null, 'INFO');
        } catch (Exception $e) {
            $this->logSection($this->job_name, $e->getMessage(), null, 'ERROR');
            throw $e;
        }
    }
4

1 に答える 1

5

インスタンス経由ClassName::methodName()はなく、クラス経由で静的メソッドを呼び出します。$instance::methodName()

于 2012-09-26T05:01:37.610 に答える