المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : [كلاس] http request



admin
11-01-2013, بتوقيت غرينيتش 01:08 PM
http://www.dzbatna.com/images/icons/iconrote.gif [ظƒظ„ط§ط³] http request (http://www.dzbatna.com/t786306/)


بسم الله الرحمن الرحيم

ازيكم ؟؟

النهاردة اول مرة استخدم كلاس من الSPL <- منتظر مباركتكم طبعا http://www.dzbatna.com/images/smilies/shiny01.gif

للعلم الSPL سهلت التعامل مع حاجات كتير ممكن نحكي عنها نبذه صغيرة
&quot;هيا اختصار لStandard Php Library و اتضافت في النسخة الخامسة من الphp اظنها افضل ما في الphp5 هاتسهل معاك التعامل مع حاجات كتير زي الarray , cache , Directory و الxml
و ايه تاني .... &quot;
اه هوه انا قلت انها ممكن تختصر معاك في عدد السطور بطريقة رهيبة ؟؟
نرجع للكلاس بقي الكلاس ده للHttp Request و له جزء تاني للResponse بس لما يخلص بقي

الكلاس

رمز PHP:

<code style="white-space:nowrap"> <code> <?php
/**
* @author: Ahmed H AboElnasser <[email protected] (http://www.cloudflare.com/email-protection)>
* @license MIT
* @since: Class available since EgySolutions Framework 0.1.1 Beta
* @link: http://www.egysolutions.net
* Requires: PHP 5.1.4+
* @package: EgySolutions Framework
* @category: core
* @subpackage: httprequest
*/



/**
* Abstraction for $_REQUEST access with methods
*/
interface RequestInterface
{
public function getParameterNames();
public function issetParameter($name);
public function getParameter($name);
public function getHeader($name);

#public function getAuthData();
public function getRemoteAddress();
}

/**
* Request class for encapsulating access to superglobal $_REQUEST
* two ways of access: via methods and via arrayaccess array handling
*
* @todo: split $_REQUEST into GET and POST with each seperate access methods
*
*/
class httprequest implements RequestInterface, ArrayAccess
{
private $parameters;

/**
* Import SUPERGLOBAL $_REQUEST into $parameters
*/
public function __construct()
{



$this->parameters = $_REQUEST;
}

/**
* List of all parameters in the REQUEST
*/
public function getParameterNames()
{
return array_keys($this->parameters);
}

/**
* isset, checks if a certain parameter exists in the parameters array
* @param
*/
public function issetParameter($name)
{
return isset($this->parameters&#91;$name&#93;);
}

/**
* get, returns a certain parameter if existing
* @param
*/
public function getParameter($name)
{
if (isset($this->parameters&#91;$name&#93;))
{
return $this->parameters&#91;$name&#93;;
}
}

/**
* Get Value of a specific http-header
* @param
*/
public function getHeader($name)
{
$name = 'HTTP_' . strtoupper(str_replace('-','_', $name));
if (isset($_SERVER&#91;$name&#93;))
{
return $_SERVER&#91;$name&#93;;
}
return null;
}

/**
* Get $_SERVER REMOTE_ADDRESS
*/
public function getRemoteAddress()
{
return $_SERVER&#91;'REMOTE_ADDR'&#93;;
}

/**
* Implementation of SPL ArrayAccess
* only offsetExists and offsetGet are relevant
*/
public function offsetExists($offset)
{
return isset($this->parameters&#91;$offset&#93;);
}

public function offsetGet($offset)
{
return $this->getParameter($offset);
}

// not setting request vars
public function offsetSet($offset, $value) {}

// not unsetting request vars
public function offsetUnset($offset)
{
//unset($this->parameter&#91;$offset&#93;);
//return true;
}
}
?> </code> </code>







ألعاب الأندرويد مجانا و حصريا (http://www.apotox.info/forum)




https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-ash4/482113_236967293114455_1193518507_n.png (http://www.dzbatna.com)
©المشاركات المنشورة تعبر عن وجهة نظر صاحبها فقط، ولا تُعبّر بأي شكل من الأشكال عن وجهة نظر إدارة المنتدى (http://www.dzbatna.com)©

استعمل مربع البحث في الاسفل لمزيد من المواضيع


سريع للبحث عن مواضيع في المنتدى