From another question:
/**
* #SWG\Post(
* path="/user/login",
* #SWG\Response(response=200, description="OK")
* )
* #SWG\Path(path="/user/", ref="#/user/login");
*/
function login() {
...
}
The above code not working - no definition coming in swagger integrated page. Do I need two definitions for same method for different URLs?
Try changing the reference to
#SWG\Path(path="/user/", ref="#/paths/~1user~1login");
OpenAPI/Swagger path references use the syntax #/paths/path_name, where path_name is the string /user/login with the special character / escaped as ~1. (This answer has more escaping examples.)
Related
I'm using Symfony 2.6 and the FOS Rest Bundle.
Param converters for PATCH , DELETE and GET requests work nicely and reduce the code in the controller actions. However for POST requests I have a problem. The default \Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter gets called every time. This results in an exception:
Unable to guess how to get a Doctrine instance from the request information.
I checked the \Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener and saw that it's always including the Doctrine param converter in the onKernelController method. From the documentation it seems that the doctrine param converter is automatically applied for all type hinted controller actions unless you set it to off:
sensio_framework_extra:
request:
converters: true
auto_convert: false
I found a kind of hacky way to prevent this. The array of param converters to be applied will be indexed by the name of the type hinted argument in the controller method (which symfony gets by reflection). If I just name my param converter the same as this type hint then the default doctrine param converter will not be added to the list of param converters. For example:
...
* #ParamConverter(
* "MyEntity",
* class="Foo\Bar\MyEntity",
* converter="my_custom_converter"
* )
*
* #param MyEntity $myEntity
* #return MyEntity
*/
public function postMyEntityAction(MyEntity $myEntity)
{
I sort of wrote this question as I was digging deeper into the code and I'm not even really sure what my question is anymore. I guess it's "Is it logical to apply multiple param converters?" or would also like to know if it's possible to turn off param converters for certain actions. Maybe my logic is completely wrong here and this isn't what param converters were intended for.
I'd appreciate any advice.
Alright, I realized where I was going wrong. It was a simple case of not returning true from my custom paramConverter apply method. If it does return true then the doctrine param converter won't be applied.
I have been refactoring a project and I have seen a class named Logger. I assume this is deprecated and unneeded. I have searched for references of it and I have seen a single code fragment, which uses it:
fCore::registerDebugCallback('Logger::log');
// Enable SQL statement printing
//
$db->enableDebugging(App::env()->get('slowQueryLog'));
$db->registerHookCallback('extracted', 'Logger::queryLogPrepare');
$db->registerHookCallback('run', 'Logger::queryLog');
I see its methods are registered as callbacks. I believe these are unnecessary and I would like to remove them to be able to remove the Logger class. However, the only way I can properly test it is to remove the part above and deploy it. This code is used by a large website, so if my assumption is wrong, then there would be a lot of damage. So, even though it would be easy to test, I would like to not face the danger of removing the chunk and getting thousands of angry emails and I reach out to you guys and ask you: is flourishlib requiring to register callbacks for debug and/or hook? For your reference I give you the relevant parts of the documentation:
registerDebugCallback:
/**
* Registers a callback to handle debug messages instead of the default action of calling ::expose() on the message
*
* #param callback $callback A callback that accepts a single parameter, the string debug message to handle
* #return void
*/
registerHookCallback:
/**
* Registers a callback for one of the various query hooks - multiple callbacks can be registered for each hook
*
* The following hooks are available:
* - `'unmodified'`: The original SQL passed to fDatabase, for prepared statements this is called just once before the fStatement object is created
* - `'extracted'`: The SQL after all non-empty strings have been extracted and replaced with ordered sprintf-style placeholders
* - `'run'`: After the SQL has been run
*
* Methods for the `'unmodified'` hook should have the following signature:
*
* - **`$database`**: The fDatabase instance
* - **`&$sql`**: The original, unedited SQL
* - **`&$values`**: The values to be escaped into the placeholders in the SQL
*
* Methods for the `'extracted'` hook should have the following signature:
*
* - **`$database`**: The fDatabase instance
* - **`&$sql`**: The SQL with all strings removed and replaced with `%1$s`-style placeholders
* - **`&$values`**: The values to be escaped into the placeholders in the SQL
*
* The `extracted` hook is the best place to modify the SQL since there is
* no risk of breaking string literals. Please note that there may be empty
* strings (`''`) present in the SQL since some databases treat those as
* `NULL`.
*
* Methods for the `'run'` hook should have the following signature:
*
* - **`$database`**: The fDatabase instance
* - **`$query`**: The (string) SQL or `array(0 => {fStatement object}, 1 => {values array})`
* - **`$query_time`**: The (float) number of seconds the query took
* - **`$result`** The fResult or fUnbufferedResult object, or `FALSE` if no result
*
* #param string $hook The hook to register for
* #param callback $callback The callback to register - see the method description for details about the method signature
* #return void
*/
I am using request object in twig extension class to get the current route. For instance, having the following url:
http://www.localhost/project/user/page/2
Inside of the twig extension I'm able to get user/page/2 string and do something with it.
The problem arises when I wanna get the default route using the same method, which I have to do. For example, accessing the following url:
http://www.localhost/project/user
I want to get user/page/1 string inside the twig extension class, and not just user.
The controller looks like this:
/**
* #Route(name="user",
* default="user/page/1")
*/
Is there a way to achieve that? Or do I have to stop using default routes?
Write a comment if you need more explanation, it's 9AM here in Poland and I'm sleeping yet.
The #Route documentation explains that you can do this for set a default page number:
/**
* #Route("/project/user/page/{page}",
* name="user",
* defaults={"page" = 1},
* requirements={"page" = "\d+"}
* )
*/
Is it possible to use file validation classes with form annotations?
/**
* #Form\Name("profile_avatar")
* #Form\Type("Zend\Form\Element\File")
* #Form\Options({"label":"Your avatar"})
* #Form\Validator({"name":"Zend\Validator\File\IsImage"})
*/
public $profile_avatar;
With code above form is always valid even if you send non-image file.
I think You have to use only "IsImage" as name... I had similar problem with Hostname valuidator. I actually didn't solved it because I can't get the options working...
I very much enjoy working in Notepad++, but I haven't yet found a plugin to automatically do PHPDoc style comments. Other PHP IDE's (Eclipse, NetBeans, ZendStudio) include this feature, and it's quite handy.
Basically what I want is, if on the line above a function definition or class definition I type in:
/**
It automatically populates the PHPdoc format (something like the following for a function):
/**
*
* #param $first_argument
* #param $second_argument
* #return
*/
Then when I type in additional lines to the comment, it starts each line with an asterisk.
Is there a NP++ plugin that accomplishes this, or a way to tweak NP++ to make it work?
The question is old...but try DoxyIt plugin from plug manager. It works exactly as you need.
While Notepad++'s syntax highlighter recognizes doc comments, it does not actually parse them and generate the corresponding autocomplete code for you, nor does it have any snippet features that allow you to insert doc comments on the fly.
Try DocIt, it works fine, after install move cursor before function and press CTRL + ALT + SHIFT + D to add comments.
Download: https://sourceforge.net/projects/nppdocit/postdownload
I think there aren't a "really tool" por PHPDoc on N++. You can use the WebEdit plugin (plugin manager). Once installed you need to update the edit file adding this line at the end:
pdoc=/**\n * \n * \n * #params \n * #return \n */
Restart N++, write pdoc and press Alt+Enter to get anything like this:
/**
*
*
* #params
* #return
*/
Obviously, it can't get your function params and other tipical info of DocBloks but may be helpfull if we have no choice.
I guess the selected answer is older than the plugin itself but I use DocIt. http://nppdocit.sourceforge.net/