mosbth / cform

A PHP-class to create, render and validate submitted HTML-forms.
http://dbwebb.se/cform
GNU General Public License v3.0
5 stars 2 forks source link

CLydia not exists #19

Closed weleoka closed 9 years ago

weleoka commented 9 years ago

Error is: Classfile 'CLydia' does not exists.

0 [internal function]: myAutoloader('CLydia')

1 [internal function]: spl_autoload_call('CLydia')

2 /apache2/htdocs/dataDB/vendor/mos/cform/src/HTMLForm/CFormElement.php(37): is_callable('CLydia::Instanc...')

Line 37 in CFormElement and the _construct()

    public function __construct($name, $attributes = []) 
    {
        $this->attributes = $attributes;    
        $this['name'] = $name;
        //$this['key'] = $name;
        //$this['name'] = isset($this['name']) ? $this['name'] : $name;

        // Use character encoding from lydia if available, else use UTF-8 OBSOLETE, remove this.
        if (is_callable('CLydia::Instance()')) {
            $this->characterEncoding = CLydia::Instance()->config['character_encoding'];
        } else {
            $this->characterEncoding = 'UTF-8';
        }
    }
weleoka commented 9 years ago

Shall I fork amend, and make pull request? Also many wasted end-of-line whitespace characters in CForm code. Clean?

mosbth commented 9 years ago

Hmm, haven't seen that become an error before. Do you have a small testprogram or any of the available testprogram that produces that error?

About end-of-line whitepspace, hold that thought, just a minute. Lets check above first.

mosbth commented 9 years ago

Feel free to add a small testprogram that shows the error, if needed, and make a pull request.

weleoka commented 9 years ago

This issue is in version 2 of CForm ( i.e. v1.9.x. Latest release: v1.9.1 on 2014-05-05 )

composer.json: require "mos/cform": "2.*@dev"

checksum: 6e58aa0c0f128af725bccd50c6a806a5d6953683

/src/HTMLForm/CFormElement.php -> _construct() is where the error is. I don't think a test case is needed? It's a piece of obsolete code?

Probably one small nothing in all the other things that need doing in V2 of CForm. =)

mosbth commented 9 years ago

Hmm, I'll check it.

mosbth commented 9 years ago

I fixed the trailing spaces, makes it easier to receive pull requests when it passes phpcs.

I also added a pre-commit-hook that runs phpcs (and phpunit).

However, I can not reproduce the error. There is a testcase in: https://github.com/mosbth/cform/blob/v2/test/HTMLForm/CFormElementTest.php#L20

which should produce the error.

Can you run phpunit whithout errors? I can. You should get the error when you try it, or?

mosbth commented 9 years ago

The code is obsolete, so it should be removed - or rewritten, however, I would really like to reproduce it to get the same error as you have.

weleoka commented 9 years ago

I pass all the tests with phpunit I did this (which I understand is the wrong way to do it!) :

    $el = new \Mos\HTMLForm\CForm();
    $form = $el->create([], [
        'test' => ['type'      => 'select'],
    ]);

And that throws:

    Fatal error: Uncaught exception 'Exception' with message 'Classfile 'CLydia' does not exists.'
mosbth commented 9 years ago

Yes, its missing an array of options. Buts its still another Exception. Perhaps, the exception you get now is from your autoloader, saying it can not find the classfile for CLydia. Ah, I see, its rather obvious in your first post. The exception is from your autoloader.

I guess its an issue with your autoloader. If you try doing this in your code:

var_dump(class_exists("NoSuchClass"));

You should get false, but you probably will get an exception, right? Your autoloader behavior disturbs the functions that tries to check if a class, or function, exists. So its an issue with your autoloader.

Nevertheless, I added both CFormException and testcases for <select> and <select multiple> to general improve CForm.

Eventually will I remove the connection to CLydia, it should not be there anymore. But the code should work with it in there.

weleoka commented 9 years ago

Absolutely true, it was my autoloader which was throwing the exception - it should have been obvious to me, but I missed that. Thanks.