unionofrad / li3_behaviors Goto Github PK
View Code? Open in Web Editor NEWModel Behaviors plugin for the li₃ PHP framework.
License: BSD 3-Clause "New" or "Revised" License
Model Behaviors plugin for the li₃ PHP framework.
License: BSD 3-Clause "New" or "Revised" License
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.