I'm trying to add user groups in my API developed using Luracast Restler using the example class "AccessControl" which implements the iAuthenticate class from Restler.
Files: https://gist.github.com/anonymous/d6a315d1f29dc7722b7d
The problem I'm having is with the method defined in AccessControl::__isAllowed() like so:
Resources::$accessControlFunction = 'AccessControl::verifyAccess';
AccessControl::verifyAccess is never called, so I can't use
$m['class']['AccessControl']['properties']['requires']
to read the requirements for the method being called in the API.
The token system I've added is simply a unique identifier based on a number of criteria which the user gets when a POST /user/token is processed with the correct information.
How can I make this work like it should? According to the docs for Restler, I should be able to have a method defined like I did and it should return a boolean value, like it does. But it never gets called, so...
Boy, do I feel stupid. Turns out I don't actually need the $accessControlFunction. I just had to use {#Requires ...} instead of {#requires ...} in my Test.php class.
Carry on, good people!
Related
Hi i am new to codeception unit testing and i am using it with Yii2. I know the user of functions expect_not() and expect_that() and also know little about expect() function and uses it to check key in error array.
However I don't know the use of expect_file(). I searched little in internet but found not any good help. can anyone please give me little description about the use of this function.
expect_file() is used to verify with assertions specific to file system objects. It has two parameters (one is optional).
If you call this function with a single parameter, it will be used as the Subject Under Test file name. if it is called with two parameters, will be used as a description to display if the assertion fails but if you if you call it with 0 or more than two arguments it will throw a bad method call exceptions.
You can use it like this
expect_file('filename.txt')->exists();
expect_file('filename.txt')->notExists();
BTW expect_file() is an alternate function for verify_file().
I'm trying to figure out if there is possibility to check requirements before processing controller action. In Nette there are methods like checkRequirements, onStartup, beforeRender where I can check this.
I have api resource album/{albumId}/song/ and I would like to check if album with given id exists every time any action on my SongController is processed and return 404 status code if not.
So far I have found this article in Symfony documentation where I found there are no methods like preExecute and postExecute. However I guess there is bundle or something like that to add those methods. I think it does not make sense to create new class to use it only in one controller.
Are there any other options to do it?
ParamConverter does that. It looks for a entity using the id supplied from the route and throws an exception, returning a 404 if it doesn't find anything.
// paramConverter requires that you type-hint a class, which is a best practice anyway :)
public function getArtist(\Appbundle\Entity\Song $song)
{
//...
}
Using Symfony, I am displaying a table with some entries the user is able to select from. There is a little more complexity as this might include calling some further actions e. g. for filtering the table entries, sorting by different criteria, etc.
I have implemented the whole thing in an own bundle, let's say ChoiceTableBundle (with ChoiceTableController). Now I would like to be able to use this bundle from other bundles, sometimes with some more parametrization.
My desired workflow would then look like this:
User is currently working with Bundle OtherBundle and triggers chooseAction.
chooseAction forwards to ChoiceTableController (resp. its default entry action).
Within ChoiceTableBundle, the user is able to navigate, filter, sort, ... using the actions and routing supplied by this bundle.
When the user has made his choice, he triggers another action (like choiceFinishedAction) and the control flow returns to OtherBundle, handing over the results of the users choice.
Based on these results, OtherBundle can then continue working.
Additionally, OtherOtherBundle (and some more...) should also be able to use this workflow, possibly passing some configuration values to ChoiceTableBundle to make it behave a little different.
I have read about the "Controller as Service" pattern of Symfony 2 and IMHO it's the right approach here (if not, please tell me ;)). So I would make a service out of ChoiceTableController and use it from the other bundles. Anyway, with the workflow above in mind, I don't see a "good" way to achieve this:
How can I pass over configuration parameters to ChoiceTableBundle (resp. ChoiceTableController), if neccessary?
How can ChoiceTableBundle know from where it was called?
How can I return the results to this calling bundle?
Basic approaches could be to store the values in the session or to create an intermediate object being passed. Both do not seem particularly elegant to me. Can you please give me a shove in the right direction? Many thanks in advance!
The main question is if you really need to call your filtering / searching logic as a controller action. Do you really need to make a request?
I would say it could be also doable just by passing all the required data to a service you define.
This service you should create from the guts of your ChoiceTableBundleand let both you ChoiceTableBundle and your OtherBundle to use the extracted service.
service / library way
// register it in your service container
class FilteredDataProvider
{
/**
* #return customObjectInterface or scallar or whatever you like
*/
public function doFiltering($searchString, $order)
{
return $this->filterAndReturnData($searchString, $order)
}
}
...
class OtherBundleController extends Controller {
public function showStuffAction() {
$result = $this->container->get('filter_data_provider')
->doFiltering('text', 'ascending')
}
}
controller way
The whole thing can be accomplished with the same approach as lipp/imagine bundle uses.
Have a controller as service and call/send all the required information to that controller when you need some results, you can also send whole request.
class MyController extends Controller
{
public function indexAction()
{
// RedirectResponse object
$responeFromYourSearchFilterAction = $this->container
->get('my_search_filter_controller')
->filterSearchAction(
$this->request, // http request
'parameter1' // like search string
'parameterX' // like sorting direction
);
// do something with the response
// ..
}
}
A separate service class would be much more flexible. Also if you need other parameters or Request object you can always provide it.
Info how to declare controller as service is here:
http://symfony.com/doc/current/cookbook/controller/service.html
How liip uses it:
https://github.com/liip/LiipImagineBundle#using-the-controller-as-a-service
I'm trying to use the waitUntilDBInstanceAvailable() to wait for my newly created instance to be available so that I can grab the endpoint name.
Note: The endpoint name is not available until the instance is fully up.
I've looked at waiters but it uses different methods params, waitUntilDBInstanceAvailable takes 1 array as an argument per documentation.
$results = $rds->waitUntilDBInstanceAvailable([
'DBInstanceIdentifier' => 'my-rds-instance'
]);
$instanceEndPoint = $results->DBInstances->EndPoint // Theoretically
Waiters share the input parameters of the operation they use. In this case, the docs say "The input array uses the parameters of the DescribeDBInstances operation", which means you can use the parameters of the DescribeDBInstances operation.
However, waiters do not return results as you have assumed in your code example. Looking at the docs, there is no return value documented. Therefore, the usage of waiters is consistent with the documentation. If you need to get data about the thing you are waiting for, then you need to follow up with a separate call after the waiting is complete.
I'm not sure what is your exact question, but check this question/answer:
Is it possible to register a callback function to waitUntilDBInstanceAvailable()?
Rather than using controller/action/key1/value1/key2/value2 as my URL, I'd like to use controller/action/value1/value2. I think I could do this by defining a custom route in my Bootstrap class, but I want my entire application to behave this way, so adding a custom route for each action is out of the question.
Is this possible? If so, how would I then access valueN? I'd like to be able to define the parameters in my action method's signature. e.x.:
// PostsController.php
public function view($postID) {
echo 'post ID: ' . $postID;
}
I'm using Zend Framework 1.9.3
Thanks!
While I don't think it's possible with the current router to allow N values (a fixed number would work) you could write a custom router that would do it for you.
I would question this approach, however, and suggest that actually listing all of your routes won't take long and will be easier in the long run. A route designed as you've suggested would mean that either your named parameters are always in the same order, i.e.
/controller/action/id/title/colour
or that they are almost anonymous
/controller/action/value1/value2/value3
With code like
$this->getRequest()->getParam('value2'); //fairly meaningless
Does it have to be N or can you say some finite value? For instance can you imagine that you'll never need more than say 5 params? If so you can set up a route:
/:controller/:action/:param0/:param1/:param2/:param3/:param4
Which will work even if you don't specify all 5 params for every action. If you ever need 6 somewhere else you can just add another /:paramN onto the route.
Another solution I've worked with before is to write a plugin which parses the REQUEST_URI and puts all the extra params in the request object in the dispatchLoopStartup() method. I like the first method better as it makes it more obvious where the params are coming from.