schmittjoh / JMSDiExtraBundle

Provides Advanced Dependency Injection Features for Symfony2
http://jmsyst.com/bundles/JMSDiExtraBundle
330 stars 130 forks source link

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

Open cedriclombardot opened 12 years ago

cedriclombardot commented 12 years ago

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
cedriclombardot commented 12 years ago

This is linked to https://github.com/symfony/symfony/commit/041286e6011f2bfbf4c39c9d64f97f6c50e88974

jonathaningram commented 12 years ago

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

luishdez commented 12 years ago

Same problem in the assetic bundle https://github.com/symfony/AsseticBundle/issues/85 , this is because

Symfony\Component\Config\Resource\ResourceInterface

has been updated recently.

symfonyluxury commented 12 years ago

so, how to resolve it? bundle maintainer?

jonathaningram commented 12 years ago

@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 commented 12 years ago

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

marfillaster commented 12 years ago

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

jonathaningram commented 12 years ago

@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 commented 12 years ago

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

stof commented 12 years ago

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

jonathaningram commented 12 years ago

@stof oh I didn't/don't mind doing the PR to try and fix it, but it's just that I wasn't entirely sure how the methods should be implemented, so I thought at the least pasting in the code would help with the PR process. I just assumed Johannes would have to create his own fork anyway if mine was wrong. And it's 5:30pm here now so I cannot stick around to go back and forth :)

On 21/06/2012, at 5:25 PM, Christophe Coevoet wrote:

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


Reply to this email directly or view it on GitHub: https://github.com/schmittjoh/JMSDiExtraBundle/issues/28#issuecomment-6475860

gajdaw commented 12 years ago

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

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

nicolas-bastien commented 12 years ago

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

stevelacey commented 12 years ago

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?

stof commented 12 years ago

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

schmittjoh commented 12 years ago

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

stevelacey commented 12 years ago

@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.

stevelacey commented 12 years ago

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

stof commented 12 years ago

@stevelacey see the comment done by @schmittjoh

stevelacey commented 12 years ago

@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 commented 12 years ago

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 commented 12 years ago

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

jonathaningram commented 12 years ago

FYI thanks all for taking the PR off my hands - I was out all night hence why I didn't make the PR myself as I knew I would be unavailable to finish the fix. Night!

On 22/06/2012, at 12:37 AM, Hubert Moutotreply@reply.github.com wrote:

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


Reply to this email directly or view it on GitHub: https://github.com/schmittjoh/JMSDiExtraBundle/issues/28#issuecomment-6483768

stevelacey commented 12 years ago

@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 commented 12 years ago

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

schmittjoh commented 12 years ago

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 commented 12 years ago

@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 commented 12 years ago

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

TomAdam commented 12 years ago

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.