Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Class JMS\DiExtraBundle\Config\FastDirectoriesResource contains 5 abstract methods #28

Open
cedriclombardot opened this Issue · 29 comments
@cedriclombardot

Hi,

Updating my deps i've this error :

Fatal error: Class JMS\DiExtraBundle\Config\FastDirectoriesResource contains 5 abstract methods and must therefore be declared abstract or implement the remaining methods (Symfony\Component\Config\Resource\ResourceInterface::getModificationTime, Symfony\Component\Config\Resource\ResourceInterface::exists, Symfony\Component\Config\Resource\ResourceInterface::getId, ...) in XXX/symfony/vendor/jms/di-extra-bundle/JMS/DiExtraBundle/Config/FastDirectoriesResource.php on line 78
@jonathaningram

FYI @schmittjoh this occurs when updating, say, via Composer.

@luishdez

Same problem in the assetic bundle symfony/AsseticBundle#85 , this is because

Symfony\Component\Config\Resource\ResourceInterface

has been updated recently.

@symfonyluxury

so, how to resolve it? bundle maintainer?

@jonathaningram

@symfonyluxury Until @schmittjoh can verify the fix, I have temporarily updated these two files (I think that they could be close to correct, but need confirmation from Johannes):

<?php

/*
 * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace JMS\DiExtraBundle\Config;

use JMS\DiExtraBundle\Finder\PatternFinder;

use Symfony\Component\Config\Resource\ResourceInterface;

class FastDirectoriesResource implements ResourceInterface
{
    private $finder;

    private $directories;
    private $filePattern;
    private $files = array();

    public function __construct(array $directories, $filePattern = null)
    {
        $this->finder = new PatternFinder('.*', '*.php');
        $this->finder->setRegexPattern(true);

        $this->directories = $directories;
        $this->filePattern = $filePattern ?: '*';
    }

    public function __toString()
    {
        return implode(', ', $this->directories);
    }

    public function getResource()
    {
        return $this->directories;
    }

    public function update()
    {
        $this->files = $this->getFiles();
    }

    public function isFresh($timestamp)
    {
        $files = $this->getFiles();

        if (array_diff($this->files, $files) || array_diff($files, $this->files)) {
            return false;
        }

        foreach ($files as $file) {
            if (filemtime($file) > $timestamp) {
                return false;
            }
        }

        return true;
    }

    public function exists()
    {
        return true;
    }

    public function getId()
    {
        return md5('jms_di_extra'.$this->filePattern.$this->files);
    }

    public function getModificationTime()
    {
        return -1;
    }

    public function serialize()
    {
        $resourceMap = array(
            'filePattern' => $this->filePattern,
            'files'       => $this->files,
        );

        return serialize($resourceMap);
    }

    public function unserialize($serialized)
    {
        $resourceMap = unserialize($serialized);

        $this->filePattern = $resourceMap['filePattern'];
        $this->files = $resourceMap['files'];
    }

    private function getFiles()
    {
        return $this->finder->findFiles($this->directories);
    }
}
<?php

/*
 * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace JMS\DiExtraBundle\Config;

use JMS\DiExtraBundle\Finder\PatternFinder;
use Symfony\Component\Config\Resource\ResourceInterface;

class ServiceFilesResource implements ResourceInterface
{
    private $files;
    private $dirs;

    public function __construct(array $files, array $dirs)
    {
        $this->files = $files;
        $this->dirs = $dirs;
    }

    public function isFresh($timestamp)
    {
        $finder = new PatternFinder('JMS\DiExtraBundle\Annotation');
        $files = $finder->findFiles($this->dirs);

        return !array_diff($files, $this->files) && !array_diff($this->files, $files);
    }

    public function __toString()
    {
        return implode(', ', $this->files);
    }

    public function getResource()
    {
        return array($this->files, $this->dirs);
    }

    public function exists()
    {
        return true;
    }

    public function getId()
    {
        return md5('jms_di_extra'.$this->files.$this->dirs);
    }

    public function getModificationTime()
    {
        return -1;
    }

    public function serialize()
    {
        $resourceMap = array(
            'files' => $this->files,
            'dirs'  => $this->dirs,
        );

        return serialize($resourceMap);
    }

    public function unserialize($serialized)
    {
        $resourceMap = unserialize($serialized);

        $this->files = $resourceMap['files'];
        $this->dirs = $resourceMap['dirs'];
    }
}

I know there's some things in there not correct, but it appears to be getting me through the day :)

@symfonyluxury

merci jonathaningram, you save me this day!!! This is nice for temporally work around <3

@marfillaster

@jonathaningram can you create a fork so we can point a custom composer repository to yours while this is not yet fixed

@jonathaningram

@marfillaster I've just edited the files locally, but you should be able to create the fork yourself just as quick as I would :D - those are the only files you need to edit (I believe).

@marfillaster

@jonathaningram yeah, also thought of maintaining a temporary local copy of hot fixed repo.

@stof

@jonathaningram by creating a fork, you could send a PR to fix the classes in the bundle :)

@jonathaningram
@gajdaw

@jonathaningram thanks. Here is a branch that contains both files:

https://github.com/gajdaw/JMSDiExtraBundle/tree/issue_28_fix

@nicolas-bastien

@gajdaw Hi so as stof sais, why you didn't make a PR if you already have done the job to correct this ?

@stevelacey

Using the fix I seem to be getting this when my cache is warm:

Notice: unserialize(): Error at offset 55 of 57 bytes in /vendor/symfony/symfony/src/Symfony/Component/Config/Resource/FileResource.php line 114

Is this related?

@aerialls aerialls referenced this issue in symfony/symfony-standard
Closed

Fatal error runnning composer update #348

@stof

@stevelacey due to the serialization change, you need to remove your cache entirely after the upgrade

@schmittjoh
Owner

@jonathaningram, I think the finder is missing in the serialize method of the FastDirectoryResource, but otherwise looks good. Could you send a PR?

@stevelacey

@stof if I remove the cache entirely the first cache-clear will succeed but then subsequent cache-clears and requests will fail with that error.

@francoispluchino francoispluchino referenced this issue in gajdaw/JMSDiExtraBundle
Closed

Fix bug issue #28 #1

@youbs youbs referenced this issue from a commit in youbs/JMSDiExtraBundle
@youbs youbs implemented missing methods, fixes issue #28 951af35
@stevelacey

I'm still getting the same error, am I missing something or is the patch not quite there yet?

@stof

@stevelacey see the comment done by @schmittjoh

@stevelacey

@stof

"I think the finder is missing in the serialize method of the FastDirectoryResource, but otherwise looks good. Could you send a PR?"?

Looks to me that was fixed in @youbs' fork?

@TomAdam

I'm using @youbs' fork, and I get the same error as @stevelacey. Adding in thr finder had not fixed the problem. I have done a manual cache clear.

[ErrorException]                                                                                                    
Notice: unserialize(): Error at offset 47 of 49 bytes in /var/www/hcc/vendor/symfony/symfony/src/Symfony/Component/Config/Resource/FileResource.php line 114
@youbs

@TomAdam @stevelacey
I don't have this error, when do you get it exactly ? after clearing your cache ?

@jonathaningram
@stevelacey

@youbs If I rm -rf my cache, then do a cache clear, no error, but subsequent requests and cache clears return error, so it's the warmed cache that's broken.

@TomAdam

Same here. Cache builds fine if its empty, but fails to rebuild afterwards.

@schmittjoh
Owner

If you are talking about "cache clear", are you manually calling php app/console cache:clear, or does the error also occur on normal re-builds of the container in development?

@stevelacey

@schmittjoh I don't entirely understand the question (pretty new to version 2), but the error occurs on cache clears (after warmup), composer updates, when accessing the project in my browser and when just running app/console, in short, everywhere.

@TomAdam

Well some good news! I no longer get the issue. Fabpot reverted the commit that caused this in the first place. See symfony/symfony@0d4b02e

@TomAdam

Just to answer the question anyway, I noticed it any time the cache was rebuilt, so a cache:clear with a primed cache and a request after a change to a file in dev would both trigger it. You could get one request through if you wiped the cache manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.