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(
);
halfer
  • 19,824
  • 17
  • 99
  • 186
LeonardChallis
  • 7,759
  • 6
  • 45
  • 76
  • 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).. – Sam Jun 13 '13 at 20:41
  • No I use the global install, so just `composer install` works. As I said above, the behaviour `require`s 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. – LeonardChallis Jun 13 '13 at 22:44
  • 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. – Sam Jun 14 '13 at 02:05
  • Yeah I tried that but no luck. Are you saying u shouldn't need to have the line in my build.properties file? – LeonardChallis Jun 14 '13 at 06:07
  • Ah I'm really not sure..I was just giving a guess. I've never installed any external propel behaviors. – Sam Jun 14 '13 at 06:14
  • 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 Composer – Mathew Jun 17 '13 at 14:41
  • No it doesn't appear so. I have updated the question with that info – LeonardChallis Jun 17 '13 at 22:07
  • that may be autoloading issue. Can you try `composer dump-autoload` – Can Geliş Jun 23 '13 at 18:46

1 Answers1

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';
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141