<?php
/**
 * Generates setters and getters out of given value and prints the code to screen, which can
 * simply be copy pasted into place
 *
 * Usage example with underscore type and array and string as elements:
 * <code>
 * $arr = array
 * (
 *	 'name',
 *   array('id', '_id')
 * );
 *
 * setnget_gen($arr, 1);
 *
 * // output:
 * //
 * // function set_name($name) { $this->name = $name; }
 * // function get_name() { return $this->name; }
 * // function set_id($id) { $this->_id = $id; }
 * // function get_id() { return $this->_id; }
 * </code>
 * 
 *---------------------------------------
 * Originally written by Kjetil Hårtveit.
 *		www.kjetil-hartveit.com
 *---------------------------------------
 *
 * @param array $arr Elements can be string or array:
 * if string, then the value will be used everywhere, including class variable name
 * if array then the first element will be method names, and (if exists) the second element
 * will be class variable name
 * @param int $type Types: 1=underscore (set_name()), 2=camelcase (setName())
 */
function setnget_gen($arr, $type=1)
{
	$str_arr = array(); # contains all the string pairs, all with an distinctive key
		foreach ($arr as $v)
		{
				if (is_array($v))
				{
					@list($name, $var_name) = $v;
					$var_name = $var_name ? $var_name : $name;
				}
				else
				{
					$name = $var_name = (string) $v;
				}

				switch ($type)
				{
					case 1: # underscore
					default: # note that type defaults to 1 if invalid type is given
						$str_arr[] = "function set_$name(\$$name) { \$this->$var_name = \$$name; }\r\n".
										"function get_$name() { return \$this->$var_name; }\r\n";
					break;
					case 2: # camelcase
						$str_arr[] = 'function set'.ucfirst($name)."(\$$name) { \$this->$var_name = \$$name; }\r\n".
										'function get'.ucfirst($name)."() { return \$this->$var_name; }\r\n";
					break;
				}
		}

	$str = implode('', $str_arr);
	echo nl2br($str);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta name="language" content="en" />
				<link rel="shortcut icon" href="/gfx/favicon.ico" />

		<title>Kjetil Hårtveit</title>
		<link rel="stylesheet" type="text/css" href="/css/combined.css" />
		<script type="text/javascript" src="/js/combined.js"></script>

		<!--[if lt IE 8]>
			<link rel="stylesheet" type="text/css" href="/css/ie7_fix.css" />
		<![endif]-->

		<script type="text/javascript">
		/*
		var _gaq = _gaq || [];
		_gaq.push(['_setAccount', 'UA-18938202-3']);
		_gaq.push (['_gat._anonymizeIp']);
		_gaq.push(['_trackPageview']);

		(function() {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();
		*/

		SyntaxHighlighter.defaults['gutter'] = false;
		SyntaxHighlighter.defaults['tab-size'] = 2;
		</script>

		<!-- Google tag (gtag.js) -->
		<script async src="https://www.googletagmanager.com/gtag/js?id=G-NX8QVLDPG3"></script>
		<script>
		  window.dataLayer = window.dataLayer || [];
		  function gtag(){dataLayer.push(arguments);}
		  gtag('js', new Date());
		  gtag('config', 'G-NX8QVLDPG3');
		</script>

			</head>
	<body>
		<div id="outerWrapper">
			<div id="wrapper">
				<div id="header">
					<table cellpadding="0" cellspacing="0" id="headerTable">
						<tr>
							<td id="headerLink">
								<a href="/"></a>
							</td>
							<td id="headerNavigation">
								<ul id="headerNavList">
									<li><a href="/">
										 Home
									</a></li>
									<li><a href="http://wordpress.kjetil-hartveit.com/">
										 WP Blog
									</a></li>
									<li class="last-child"><a href="/blog/">
										 Blog (no longer maintained)
									</a></li>
									<!--<li class="last-child"><a href="/personlig-hjemmeside/">
										 Personlig hjemmeside <img src="/gfx/no.png" alt="(in norwegian)" />
									</a></li>-->
								</ul>
							</td>
						</tr>
					</table>
				</div>
				<table cellpadding="0" cellspacing="0" id="contentWrapper">
					<tr>
						<td>
							<div id="content">
															</div>
						</td>
						<td>
							<div id="rightBox">
								<div id="navigationWrapper">
									<ul id="navigation">
										<li class="navBotBorder"><a href="/">Home</a></li>
<li class="navBotBorder"><a href="/about">About</a></li>
<li class="navBotBorder"><a href="/projects/">Projects</a></li>
<li><a href="/contact">Contact</a></li>

																						<li class="navSection"><a style="padding: 0;" href="http://wordpress.kjetil-hartveit.com">Last blog posts</a></li>
																								<li class="navBotBorder"><a href="http://wordpress.kjetil-hartveit.com/2014/09/08/how-to-assign-a-ringtone-to-your-iphone-5-from-the-itunes-store/">How to assign a ringtone to your iPhone 5 from the iTunes Store</a></li>
																										<li class="navBotBorder"><a href="http://wordpress.kjetil-hartveit.com/2014/07/17/mvc-2-model-binding-happens-automatically-for-properties-not-fields/">MVC 2 – Model binding happens automatically for properties not fields</a></li>
																										<li class="navBotBorder"><a href="http://wordpress.kjetil-hartveit.com/2014/06/16/dom-attribute-change-events-and-how-it-can-improve-maintainability-in-your-web-application/">HTML/DOM attribute change events and how it can improve maintainability in your web application</a></li>
																										<li class="navBotBorder"><a href="http://wordpress.kjetil-hartveit.com/2014/06/04/google-api-nightmare-how-i-fixed-the-could-not-load-file-or-assembly-system-net-http-primitives-version1-5-0-0-exception/">Google API nightmare: How I fixed the “Could not load file or assembly ‘System.Net.Http.Primitives, Version=1.5.0.0 …” exception</a></li>
																										<li class=""><a href="http://wordpress.kjetil-hartveit.com/2014/02/04/how-to-access-array-elements-of-a-vbscript-class-property-returning-an-array/">How to access array elements of a VBScript class property (returning an array)</a></li>
																							</ul>
								</div>

								<br />

								<!-- start twitter feed -->

								<!--<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'profile',
  rpp: 3,
  interval: 6000,
  width: 230,
	height: 60,
  theme: {
    shell: {
      background: '#545454',
      color: '#ffffff'
    },
    tweets: {
      background: '#ffffff',
      color: '#000000',
      links: '#002bff'
    }
  },
  features: {
    scrollbar: false,
    loop: false,
    live: false,
    hashtags: true,
    timestamp: true,
    avatars: false,
    behavior: 'all'
  }
}).render().setUser('KjetilHaartveit').start();
</script>-->

								<!-- end twitter feed -->

															</div>
						</td>
					</tr>
				</table>
				<div id="footer">
					<a href="/contact">Kjetil Hårtveit</a> &copy; 2010-2014.
					All rights reserved
					
					- 
					 <a href="/terms-of-service">Terms of Service</a> - 
					 <a href="/privacy-policy">Privacy Policy</a> - 
					 
					Best viewed in
					<a href="http://www.mozilla.com/firefox/" target="_blank">Mozilla Firefox</a>
					<a href="http://www.mozilla.com/firefox/" target="_blank">
						<img src="/img/firefox_icon.png" alt="Firefox icon"
								 style="vertical-align: bottom;" /></a>
				
				</div>
			</div>
		</div>
		<script type="text/javascript">
		SyntaxHighlighter.all();
		</script>
	</body>
</html>