Search
Learn
Share

Visual studio encapsulated attribute for PHP

If you use Visual studio with some PHP extension (like PHP Tools, for example) maybe this snippet will be helpful.
Just save it on your PC and import in visual studio with : Tools->Code snippet manager.

Now you can use it writing: "setget" +tab button.

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>attribute pack</Title>
<Author>Andrea Vincenzo Abbondanza</Author>
<Description>Encapsulate methods for an attribute</Description>
<Shortcut>setget</Shortcut>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>attr</ID>
<ToolTip>The attribute's name</ToolTip>
<Default>NAME</Default>
</Literal>
<Literal>
<ID>this</ID>
<ToolTip>This element</ToolTip>
<Default>$this</Default>
</Literal>
<Literal>
<ID>phpSimbol</ID>
<ToolTip>$</ToolTip>
<Default>$</Default>
</Literal>
<Literal>
<ID>param</ID>
<ToolTip>$param</ToolTip>
<Default>$val</Default>
</Literal>

</Declarations>
<Code Language="php">
<![CDATA[private $$$attr$;
public function Set$attr$($param$)
{
$this$->$attr$ = $param$;
}
public function Get$attr$()
{
return $this$->$attr$;
}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>