So, the question pretty much explains what i want. Here is the minimum code of what i am doing.
class AuthorizeController extends Controller
{
private $aNetEnvironment;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->aNetEnvironment = env('ANetEnvironment');
}
public function setEnvironment()
{
$controller = new AnetController\GetCustomerProfileController($request);
// $this->aNetEnvironment = SANDBOX
$response = $controller->executeWithApiResponse(
\net\authorize\api\constants\ANetEnvironment::$this->aNetEnvironment
);
}
}
Searching stackoverflow i got two options, have tried both with no luck.
Trying, {$this->aNetEnvironment} gives
syntax error, unexpected ')', expecting '('
Trying, $$this->aNetEnvironment gives
Object of class App\Http\Controllers\AuthorizeController could not be converted to string
Edit:
Trying, ${$this->aNetEnvironment} gives
Access to undeclared static property: net\authorize\api\constants\ANetEnvironment::$SANDBOX
Is there any other option ?
You could make use of the PHP's constant() helper. From the docs:
Signature:
constant ( string $name ) : mixedReturn the value of the constant indicated by name.
constant()is useful if you need to retrieve the value of a constant, but do not know its name. I.e. it is stored in a variable or returned by a function.This function works also with class constants.
So in your case:
$response = $controller->executeWithApiResponse(
constant('\net\authorize\api\constants\ANetEnvironment::' . $this->aNetEnvironment)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With