Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Propel behaviours with Composer

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(
);
like image 955
LeonardChallis Avatar asked Jun 07 '13 08:06

LeonardChallis


1 Answers

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';
like image 112
Jens A. Koch Avatar answered Oct 28 '22 23:10

Jens A. Koch