Installing Propel behaviours with Composer
Asked Answered
V

1

20

I'm currently developing on Windows with WampServer and have Composer working (with OpenSSL), with Propel installed without issue, and everything seems to work fine. However, my project now needs to make use of the Equal Nest Behaviour found here.

I thought this would allow me to use the propel behaviour. In my schema.xml I have the following snippet:

<table name="friend">
  <behavior name="equal_nest">
    <parameter name="parent_table" value="user" />
  </behavior>
</table>

But when I run propel-gen sql I get the error:

[phingcall] Unknown behavior "equal_nest"; make sure you configured the propel.be
havior.equal_nest.class setting in your build.properties

The documentation says:

Then, if you don't use Composer, or an autoloader in your application, add the following configuration to your build.properties or propel.ini file:

Making me presume that I didn't have to put in the build.properties file. However, putting it in gives me the following error:

PHP Fatal error:  Class 'EqualNestParentBehavior' not found in C:\home\movesleag
ue.com\vendor\craftyshadow\propel-equalnest-behavior\src\EqualNestBehavior.php o
n line 74

I wasn't sure if that was something to do with autoloading not working or namespaces (my schema has a namespace, but I get this same error when removing it too).

My composer.json file looks like this:

{
    "require": {
        "craftyshadow/propel-equalnest-behavior": "dev-master"
    }
}

Note: I did have Propel in there itself, but as the equalnest behaviour requires it itself I'm just letting that do its job.

So, what's the correct way to use Propel behaviours with Composer, and if I'm doing it right, why do I see the errors above?

Updates

I added this line to the top of EqualNestBehaviour.php:

include __DIR__ . DIRECTORY_SEPARATOR . 'EqualNestParentBehavior.php';

And the SQL seems to be generated correctly without errors. However, changing that file doesn't seem clever to me! Could it be a problem with autoloading? Is there anything you can think of that I can do to test that?

I can confirm that using Equal Nest Behaviour in my actual Propel code works fine, using functions like addFriends() - this is with the above changes still in place.

In my autoload_namespaces.php file I have the following:

<?php

// autoload_namespaces.php generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
);
Venezuela answered 7/6, 2013 at 8:30 Comment(8)
I'm assuming you did a php composer.phar install? Maybe try installing both Propel and the Behavior through Composer (it seems that just the Behavior is)..Papagena
No I use the global install, so just composer install works. As I said above, the behaviour requires Propel 1.6.* itself. Of course, propel is installed ad working or I wouldn't be able to see the error messages from Propel at all.Venezuela
Oh I missed the behavior including Propel 1.6. It definitely seems like an auto-loading issue, I would try it with Propel in the Composer file -- just in case.Papagena
Yeah I tried that but no luck. Are you saying u shouldn't need to have the line in my build.properties file?Venezuela
Ah I'm really not sure..I was just giving a guess. I've never installed any external propel behaviors.Papagena
Do you have a class mapping in vendor/composer/autoload_namespaces.php? I think it's this file that takes care of the autoloading, and is why the docs say you shouldn't need the config param if you're using ComposerDorweiler
No it doesn't appear so. I have updated the question with that infoVenezuela
that may be autoloading issue. Can you try composer dump-autoloadShawna
E
2

This is an autoloading issue.

Please check that you have

propel.behavior.equal_nest.class = vendor.craftyshadow.propel-equalnest-behavior.src.EqualNestBehavior

in your build.properties (for Propel).

Please check that the composer generated autoloader file is included during the bootstrap process of your application. Composer generates a "vendor/autoload.php" file. If you include it, then you get autoloading for free. And everything installed by Composer is found automatically.

require 'vendor/autoload.php';
Efflorescence answered 1/8, 2013 at 19:41 Comment(1)
Yes, the autoload is a far better way of doing things. Thank you.Venezuela

© 2022 - 2024 — McMap. All rights reserved.