For fast class prototyping I'm looking for a way to create methods declaration from it's call.
Example :
I'm writing.
$this->doStuff($action);
Magic happens. Following code is generated :
function doStuff ($action) {
//My cursor is here
}
Is it possible with PhpStorm ?
I saw code extraction implementation, it's nice, but it's not the same. Getters and setters inserting is not the same also, because a class property should be declared initially.
Alt + Enter while having caret on such call and choose appropriate option from there.
Related
When you write public function __ PhpStorm prompt's a list of Magic Methods
So if you, for instance, want to create a constructor for your class, you would use __construct magic method. For example, I typed __con and PhpStorm detect's my intention of creating a constructor thus a prompt window suggests me to auto-create one.
Once you hit Enter the method is created.
While this is pretty nice, I would really love to have the cursor automatically placed between parenthesis like this: public function __construct(|) (the vertical bar "|" illustrates the cursor), and that would give me the ability to write the params needed for the constructor, in case I don't need any properties, I could press Tab and the cursor would move to the body of the method like this:
public function __construct()
{
|
}
From what I read in PhpStorm documentation, I did not found anywhere to be mentioned that you can edit those suggestions by PhpStorm, so I believe that in order to archive what I'm describing I have to go with a live template like this:
So my question is: Is my approach the only way to archive that or there is a way to edit the PhpStorm build-in suggestion for the class constructor magic method?
Thanks!
This is a known problem, please vote for WI-33646.
What is the best way to bind a property to a component in Flex?
Say I have to update the text field of a TextArea. We can do it in two ways:
1.
AS3:
[Bindable]
private var myText:String;
//setters getters
MXML:
<mx:TextArea id="description" text="{myText}"/>
2.
AS3
private var myText:String;
private var myTextChanged:Boolean;
public set myText(pText: String): void
{
if (myText != pText)
{
myText = pText;
myTextChanged = true;
invalidateProperties();
}}
override protected function commitProperties():void
{
//other code
if (myTextChanged)
{
description.text = myText;
myTextChanged = false;
}
MXML
<mx:TextArea id="description"/>
AFAIK, the second way is clean, but has lot of code and extra variables (dirty flag). But I am not sure about the first way as I see Bindable tag is not preferred for performance implications.
Anyone with any thoughts?
Thanks in advance.
In your particular lightweight example the answer is… there is no difference. But that's only because I know the TextInput.text property uses the second method and commitProperties.
If you set the TextInput.text property 1000 times it will only draw once.
Not all code functions this way even though the framework prescribes it… it does not enforce it and sometimes when you're setting a property with bindings it can kick off many other methods behind the simple property set and does not use commitProperties and invalidation to batch the updates.
Also the code that the compiler generates for binding is not efficient. If you have a mobile project I would avoid bindings.
Also you're not binding to an object and a property (i.e. myObject.myText) but a simple string. This is where binding is useful. You're example falls down in this case and would require dispatching a custom event from myObject when the myText property changes.
Binding is always inefficient in that the code that's generated is verbose and is not as simple as a callback or using invalidation. That being said it's almost always acceptable from a performance standpoint to use bindings in place of writing a bunch of code to do exactly the same thing.
Another gotcha is that bindings are also static in nature. In other words… they exist in the global scope and cause user interface elements to stick around and not be garbage collected. A good example of this is binding to the data property in an itemRenderer that get's recycled. It is always a bad idea to use data binding in an item renderer because of this. You should override the set data(v:Object):void and/or use commitProperties.
For the record… I like binding… I use it all the time. You just have to understand that:
There is a performance hit.
It doesn't obey Flex's invalidation model (i.e. commitProperties)
It occurs in the global scope and can cause objects to hang around.
If you want to have a look at the code the compiler generates you can add a compiler option:
-keep-generated-actionscript=true
I'm currently working on a project that involve a re-implementation of the Array class.
This object needs to be an Array for compatibility reasons, while I also need to keep control of what is written in.
I cannot seem to find any way to check property creation inside of a dynamic object in AS3. Something that would work like the Event.ADDED_TO_STAGE but, like, ClassEvent.PROPERTY_ADDED.
I override methods like push, splice etc, but I cannot control direct assignation : MyArray[i] = ...
Is such a thing even possible ?
Of course, I could make some kind of validations elsewhere, but this would involve accessing a part of the code I cannot modify.
Thanks for your time !
I'm not sure I follow you entirely but you may be looking for the Proxy class:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Proxy.html
An example at the bottom shows you how you can override direct assignment:
override flash_proxy function setProperty(name:*, value:*):void {
_item[name] = value;
}
Using this you would be able to dispatch a custom event that would be fired any time an item was added to your ProxyArray
I am still learning PHP so my question may seem a little obvious but...
My question relates to opencart but is probably quite a common practice on many websites. I am creating a opencart module and in that module i have several buttons that complete different tasks. Now I have assigned the button the correct 'href' with the path and appropriate action. eg
$this->data['dosomething'] = $this->url->link('module/modulename/dosomething', 'token=' . $this->session->data['token'], 'SSL');
Note: I have called the module and action a general name for the purposes of my question.
In the controller I then have a private function called 'index', followed by a private function called 'dosomething' like below
public function index() {
* insert code *
}
public function dosomething() {
*insert code*
$this->redirect($this->url->link('module/modulename', 'token=' . $this->session->data['token'], 'SSL'));
}
Now, I would like to know how do I get the button to direct to the module controller and then run the 'dosomething' function. I could put something information in the link, ie action=dosomething and do it this way but most of opencart simply uses the text of the last / as the action. If I use the href stated above I get a error as it is trying to find the controller and template located in 'module/modulename/dosomething' rather than the controller and template located in 'module/modulename' USING the function 'dosomething'.
I hope this makes sense. I see that many other scripts in opencart successfully use this method but I just cant figure out how? I am sure I missing something obvious.
What you are doing is correct. OpenCart's framework will use the third piece of the route if specified as the method. If you try
public function dosomething() {
die('OK');
}
Then go to the url you've got, it should just show a blank white page with OK written on it. My guess is the error doesn't actually relate to the controller being an issue, and more to do with something else you've done. Either that, or the method and the third part of the route aren't a match, or the dosomething method isn't public
another flashbuilder brainbreaker for me...
I have a class with a contstructor that should only change the source of an image.
[Bindable]
[Embed(source='../pictures/test.jpg')]
private var _picture:Class;
public function Test(newSource:*****)
{
_picture.source = newSource;
}
(the image is not an image, but a class, I am aware of this, it is meant to be so :-) )
The problem is that when I call the constructor, let's say:
var test:Test = new Test(pictureAtStage.source);
Flashbuilder will give an error, becouse I can't tell the compiler what data type "newSource" at the constructor will have...
*edit:
When i use _picture.source, the embedded source does not seem to be changed...?
Anyone knows an answer?
Are we talking about mx.controls.Image? if so, then the source of an image can be: a Class, a Bitmap (not a BitmapData), a String (in which case it is assumed that you wanted to load it instead of using an embedded one). If you want to find a common denominator for all these, then Object is that class, however, I would rather limit it to something particular to your use case.
However, if I may advise anything... don't use mx.controls.Image, it's too bloated, even for Flex framework. If it must be a UIComponent - extend UIComponent and let the source be of type BitmapData - this way you will be able to manage resources better - you could reuse the same actual image for example. You could then use graphics property of the control to display the image.
Another advise, if you are still here :) Don't use [Bindable], especially the short version of it, especially not on a private variable - you will save yourself the frustration of countless hours of debugging it... Besides, in your case you aren't going to change the value of that variable anyway...
Are you still here? Well, don't use [Embed] on variables, use it on class definition - slightly more work for you, but this will, potentially, make your code more portable. If you embed on class the compiler will not generate a silly "something-something-Asset" class, it will use Bitmap or BitmapData - whichever your class extends. Thus, you will not introduce a dependency on Flex framework, and, in general, you will have more control over your code.
EDIT: the above was written assuming that _picture (class) variable and _picture (some variable used in a function) are not the same thing. But if they are the same thing, then Class class is dynamic, which means that you can add to it properties at runtime (don't know why, it's a design decision by Adobe...), however, the compiler will act as if it's not possible, so you would work around that by adding the property through reflection:
var _picture:Class = Sprite;
_picture["source"] = whatever;
trace(Sprite["source"]);
This is indeed slightly confusing, It will be of the type BitmapAsset which extends Bitmap. So any of those will work.
Since I'm very new to flashbuilder I didn't see the obvious solutions...
The solution for the first part of my question (before the edit):
Setting the data type to Object did the trick:
[Bindable]
[Embed(source='../pictures/test.jpg')]
private var _picture:Class;
public function Test(newSource:Object)
{
_pucture.source = newSource;
}