Zend 2 annotations and file validators - php

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...

Related

Get name, locale etc in laravel

This may be very easy but I just can't find it.
When we use getLocale() we get value from config.app file, right?
In that file I have 'locale'=>'en'
Also there are other things like 'name', when I try to use app()->getName() or app()->name() it says it doesn't exist.
It works with config('app.name') same as config('app.locale'), I would like to know how does it work with locale but doesn't work for name?
Also I was searching for these methods getLocale but I can't find them that's main reason why am I asking this.
The function is declared at line 1039 in the Application class (Illuminate/Foundation/Application.php:1039) of Laravel 5.6.
That's why it's working for app()->getLocale() and not app()->getName().
/**
* Get the current application locale.
*
* #return string
*/
public function getLocale()
{
return $this['config']->get('app.locale');
}

Swagger php two path having same method without repetitive doctrine annotation

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.)

Enable Symfony AppCache, but tag routes to be exempt?

Reading the Symfony Reverse Proxy Cache docs such as this I have a need for this, but I'd like to just prevent the caching from happening on certain routes overall.
Perhaps an annotation or regex setting somewhere, just to say something like
/**
* #Route("/my/route", name="my_route", cachable=false)
*/
or
/**
* #Route("/my/route", name="my_route")
* #ProxyCache(false)
*/
Is there something like this, or a composer package that does this?
You can use the FOSHttpCacheBundle, it allows you a fine tuning of what should be cached or not. For example, a given action.

Get default route from dependency injection services

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+"}
* )
*/

PHPDoc Comments in Notepad++?

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/

Categories