Giter Club home page Giter Club logo

li3_behaviors's People

Contributors

djordje avatar jails avatar jamesgol avatar mariuswilms avatar nateabele avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

jamesgol

li3_behaviors's Issues

Unable to access updated entity values from inside behavior method.

When accessing entity values inside a behavior, some work and some don't. I assume this is a misunderstanding or bad implementation on my part but for the life of me I can't figure out what's going on. Here's the test code:

<?php
use li3_behaviors\data\model\Behavior;

class BtcPayment extends Behavior
{
    protected static $_defaults = ['fields' => ['btc_received_value', 'btc_required_value']];

    public function completePayment($model, $behavior, $entity, $secret)
    {
        if (!isset($entity->btc_recieved_value, $entity->btc_transaction_hash)) {
            return 'value and hash not set';
        }

        if ($this->_verifyAmount($entity) && $this->_verifySecret($entity, $secret)) {
            return $entity->completeDonation();
        } else {
            return 'amount or secret not verified';
        }
    }
}

//--- implementation code:

use app\models\Donation;

Donation::bindBehavior('BtcPayment');

$secret = htmlspecialchars($_GET['secret']);
$donation_id = htmlspecialchars($_GET['donation_id']);
$transaction_hash = htmlspecialchars($_GET['transaction_hash']);
$destination_address = htmlspecialchars($_GET['address']);
$value_in_satoshi = htmlspecialchars($_GET['value']);

$donation = Donation::find($donation_id);

$donation->btc_transaction_hash = $transaction_hash;
$donation->btc_received_value = $value_in_satoshi;
$donation->save();

$response = $donation->completePayment($secret);

echo $response;

The above code outputs: "value and hash not set"

I've tried removing the ->save() method right above it, i've tried disabling validation (->save(null, ['validate' => false]). Nothing fixes it.

Wrong behavior method executed

So I have 2 behaviors on a model, each one has it's own methods that are unique to it, but both share a single common method name that basically does the same thing but slightly differently depending on the behavior. For some reason though, when executing this method on the second listed behavior, the code tries to execute the method on the first behavior instead.

I've gone over the code, time and time again, the behavior is set only once, at the top of the page, and it's set properly. The two matching methods do have different signatures though, im not sure if that is why it's happening.

I'm using lithium 1.1 with li3_behaviors 2.0.

Here's the offending code (only included relevant parts):

class Donation extends Model
{
    use Behaviors;

    protected $_actsAs = [
        'StripeDonation' => ['devMode' => false],
        'BtcDonation' => ['fields' => ['btc_received_value', 'btc_required_value']]
    ];

}

class StripeDonation extends Behavior
{
    protected static $_defaults = ['devMode' => false];

    public function completePayment($model, $behavior, $entity, $token, $email) {}
}

class BtcDonation extends Behavior
{
   protected static $_defaults = ['fields' => ['btc_received_value', 'btc_required_value']];

   public function completePayment($model, $behavior, $entity, $secret) {}
}

#Implementation

use app\models\Donation;

Donation::bindBehavior('BtcDonation');

$donation = Donation::find(3);
$donation->completePayment('thesecret');

#Error received: Missing argument 5 for  
#app\extensions\data\behavior\StripeDonation::completePayment(), called in
# /data/base/libraries/lithium/core/Object.php on line 146 and defined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.