1 : <?php
2 : /**
3 : * This file is part of phpUnderControl.
4 : *
5 : * PHP Version 5.2.0
6 : *
7 : * Copyright (c) 2007-2008, Manuel Pichler <mapi@phpundercontrol.org>.
8 : * All rights reserved.
9 : *
10 : * Redistribution and use in source and binary forms, with or without
11 : * modification, are permitted provided that the following conditions
12 : * are met:
13 : *
14 : * * Redistributions of source code must retain the above copyright
15 : * notice, this list of conditions and the following disclaimer.
16 : *
17 : * * Redistributions in binary form must reproduce the above copyright
18 : * notice, this list of conditions and the following disclaimer in
19 : * the documentation and/or other materials provided with the
20 : * distribution.
21 : *
22 : * * Neither the name of Manuel Pichler nor the names of his
23 : * contributors may be used to endorse or promote products derived
24 : * from this software without specific prior written permission.
25 : *
26 : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 : * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 : * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 : * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 : * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 : * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 : * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 : * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 : * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 : * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 : * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 : * POSSIBILITY OF SUCH DAMAGE.
38 : *
39 : * @category QualityAssurance
40 : * @package PhpUnderControl
41 : * @subpackage Documentation
42 : * @author Manuel Pichler <mapi@phpundercontrol.org>
43 : * @copyright 2007-2008 Manuel Pichler. All rights reserved.
44 : * @license http://www.opensource.org/licenses/bsd-license.php BSD License
45 : * @version SVN: $Id: PhpUnderControl.php 2631 2008-03-18 15:23:55Z mapi $
46 : * @link http://www.phpundercontrol.org/
47 : */
48 :
49 : require_once dirname( __FILE__ ) . '/MergeCodeHelper.php';
50 :
51 : /**
52 : * Documentation/Example/Test class for environment specific code.
53 : *
54 : * @category QualityAssurance
55 : * @package PhpUnderControl
56 : * @subpackage Documentation
57 : * @author Manuel Pichler <mapi@phpundercontrol.org>
58 : * @copyright 2007-2008 Manuel Pichler. All rights reserved.
59 : * @license http://www.opensource.org/licenses/bsd-license.php BSD License
60 : * @version Release: @package_version@
61 : * @link http://www.phpundercontrol.org/
62 : */
63 : class phpucMergeCode
64 : {
65 : /**
66 : * Return used sapi.
67 : */
68 : const SAPI = 1;
69 :
70 : /**
71 : * Return used php version
72 : */
73 : const VERSION = 2;
74 :
75 : /**
76 : * Return tested class name.
77 : */
78 : const NAME = 3;
79 :
80 : /**
81 : * Return normal token.
82 : */
83 : const NORMAL = 1;
84 :
85 : /**
86 : * Return reverse token.
87 : */
88 : const REVERSE = 2;
89 :
90 : /**
91 : * Return base64 token.
92 : */
93 : const BASE64 = 3;
94 :
95 : /**
96 : * Returns a php version specific token.
97 : *
98 : * @return string
99 : */
100 : public function versionSpecific()
101 : {
102 1 : $helper = new phpucMergeCodeHelper();
103 :
104 1 : $value = null;
105 1 : if (version_compare(phpversion(), '5.2.0') === 0)
106 1 : {
107 0 : $value = $helper->version520();
108 0 : }
109 1 : else if (version_compare(phpversion(), '5.2.5') === 0)
110 1 : {
111 0 : $value = $helper->version525();
112 0 : }
113 : else
114 : {
115 1 : $value = $helper->versionAny();
116 : }
117 1 : return $value;
118 : }
119 :
120 : /**
121 : * Returns a not version specific token.
122 : *
123 : * @param integer $what What token?
124 : * @param integer $mode Reverse, normal or base64 token string?
125 : *
126 : * @return string
127 : */
128 : public function notVersionSpecific($what, $mode)
129 : {
130 1 : $value = null;
131 : switch ( $what )
132 : {
133 1 : case self::SAPI:
134 1 : if ( $mode === self::REVERSE )
135 1 : {
136 0 : $value = strrev( php_sapi_name() );
137 0 : }
138 1 : else if ( $mode === self::BASE64 )
139 1 : {
140 0 : $value = base64_encode( php_sapi_name() );
141 0 : }
142 : else
143 : {
144 1 : $value = php_sapi_name();
145 : }
146 1 : break;
147 :
148 0 : case self::VERSION:
149 0 : if ($mode === self::REVERSE)
150 0 : {
151 0 : $value = strrev( phpversion() );
152 0 : }
153 0 : else if ( $mode === self::BASE64 )
154 0 : {
155 0 : $value = base64_encode( phpversion() );
156 0 : }
157 0 : else if ( $mode === self::NORMAL )
158 0 : {
159 0 : $value = phpversion();
160 0 : }
161 0 : break;
162 :
163 0 : case self::NAME:
164 : switch ($mode)
165 : {
166 0 : case self::REVERSE:
167 0 : $value = strrev( __CLASS__ );
168 0 : break;
169 :
170 0 : case self::NORMAL:
171 0 : $value = __CLASS__;
172 0 : break;
173 :
174 0 : default:
175 0 : $value = base64_encode( __CLASS__ );
176 0 : break;
177 0 : }
178 0 : }
179 1 : return $value;
180 : }
181 :
182 : /**
183 : * Adds two values.
184 : *
185 : * @param integer $x Test value one.
186 : * @param integer $y Test value two.
187 : *
188 : * @return integer
189 : */
190 : public function calculate( $x, $y )
191 : {
192 4 : return ( $x + $y );
193 : }
|