/**
  * Connect
  *
  * @param   bool reconnect default FALSE
  * @return  bool success
  * @throws  rdbms.SQLConnectException
  */
 public function connect($reconnect = FALSE)
 {
     if ($this->handle->connected) {
         return TRUE;
     }
     // Already connected
     if (!$reconnect && NULL === $this->handle->connected) {
         return FALSE;
     }
     // Previously failed connecting
     try {
         $this->handle->connect($this->dsn->getUser(), $this->dsn->getPassword());
         $this->_obs && $this->notifyObservers(new DBEvent(__FUNCTION__, $reconnect));
     } catch (IOException $e) {
         $this->handle->connected = NULL;
         $this->_obs && $this->notifyObservers(new DBEvent(__FUNCTION__, $reconnect));
         throw new SQLConnectException($e->getMessage(), $this->dsn);
     }
     try {
         // Figure out sql_mode and update formatter's escaperules accordingly
         // - See: http://bugs.mysql.com/bug.php?id=10214
         // - Possible values: http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
         // "modes is a list of different modes separated by comma (,) characters."
         $modes = array_flip(explode(',', this(this($this->handle->consume($this->handle->query("show variables like 'sql_mode'")), 0), 1)));
     } catch (IOException $e) {
         // Ignore
     }
     // NO_BACKSLASH_ESCAPES: Disable the use of the backslash character
     // (\) as an escape character within strings. With this mode enabled,
     // backslash becomes any ordinary character like any other.
     // (Implemented in MySQL 5.0.1)
     isset($modes['NO_BACKSLASH_ESCAPES']) && $this->formatter->dialect->setEscapeRules(array('"' => '""'));
     return parent::connect();
 }
Exemple #2
0
 /**
  * @test
  */
 public function it_provides_five_entry_points()
 {
     $instances = [it(null), this(null), these(null), those(null), that(null)];
     foreach ($instances as $instance) {
         $this->assertInstanceOf("Essence\\Essence", $instance);
     }
 }
 function hapus($id)
 {
     $result = $this->guestbook_model->DeleteData(array('id' => $id));
     if ($result == 1) {
         echo "<h2>Sukses Menghapus Buku Tamu</h2>";
         echo "<p><a href='" . this()->base_url . "/bukutamu/page'>Kembali ke halaman depan</a></p>";
     }
 }
 /**
  * Parse annotations from string
  *
  * @throws  lang.FormatException in case the annotations cannot be parsed
  */
 protected function parse()
 {
     if (is_array($this->_parsed)) {
         return;
     }
     // Short-cuircuit: We've already parsed it
     $this->_parsed = array();
     if ($this->annotations) {
         foreach (this(XPClass::parseAnnotations($this->annotations, $this->getClassName()), 0) as $name => $value) {
             $this->_parsed[$name] = new AnnotationDoc($name, $value);
         }
     }
 }
 public function create(HttpResponse $response, $user, SecureString $pass)
 {
     if (!$this->required($response)) {
         throw new IllegalStateException('Request had not been rejected, will not create authorization.');
     }
     if (1 != sizeof($response->header(self::AUTH_HEADER))) {
         throw new IllegalStateException('No authentication type indicated.');
     }
     $header = this($response->header(self::AUTH_HEADER), 0);
     foreach ($this->impl as $impl) {
         if (0 == strncmp($impl['startsWith'], $header, strlen($impl['startsWith']))) {
             try {
                 return XPClass::forName($impl['impl'])->getMethod('fromChallenge')->invoke(null, array($header, $user, $pass));
             } catch (TargetInvocationException $e) {
                 throw $e->getCause();
             }
         }
     }
     throw new IllegalStateException('Unknown authorization type.');
 }
 /**
  * Fetches a ZIP file
  *
  * @param   string url
  * @return  io.archive.zip.ZipArchiveReader
  */
 protected function zipballOf($url)
 {
     $headers = array();
     do {
         Console::write('>> ', $url, ': ');
         $response = $this->connectionTo($url, $headers)->get();
         switch ($response->statusCode()) {
             case HttpConstants::STATUS_OK:
                 Console::writeLine('Ok');
                 return ZipFile::open($response->getInputStream());
             case HttpConstants::STATUS_FOUND:
             case HttpConstants::STATUS_SEE_OTHER:
                 Console::writeLine('Redirect');
                 $headers['Referer'] = $url;
                 $url = this($response->header('Location'), 0);
                 continue;
             default:
                 Console::writeLine('Error');
                 throw new IllegalStateException('Unexpected response for ' . $url . ': ' . $response->toString());
         }
     } while (1);
     // Unreachable
 }
Exemple #7
0
            echo "Not enough force to fly, give it some gas.\n";
        } else {
            echo "Flying...\n";
        }
    };
    return this();
}, 'plane');
/**
 * This is a derived "amphibious" object of the "car" and "plane" type. It is also a derived
 * of the "vehicle" type because of "car" and "plane". This allows multiple inheritance. This
 * object can "roll" and "fly" without having to implement any logic.
 */
$amphibious = proto(function ($engine) use($car, $plane) {
    proto($car($engine));
    proto($plane($engine));
    return this();
}, 'amphibious');
// We create an engine
$mEngine = clone $engine(8);
// We create a car, give it gas and make it roll
$mCar = clone $car($mEngine);
$mCar->gas();
$mCar->roll();
// We create a plane, give it gas and make it fly
$mPlane = clone $plane($mEngine);
$mPlane->gas();
$mPlane->gas();
$mPlane->fly();
// We create an amphibious vehicle, transfer the plane engine into it, make it roll, then fly
$mAmphib = clone $amphibious($mPlane->engine);
$mAmphib->roll();
 public function builtin_array_parameters_handled_correctly()
 {
     $proxy = $this->newProxyWith('{ public function fixture(array $param); }');
     $this->assertEquals(\lang\Primitive::$ARRAY, this($proxy->getMethod('fixture')->getParameters(), 0)->getTypeRestriction());
 }
<script type="text/javascript" language="Javascript">

    // We load inline javascript files as views
    // we will build it in <head> tags
    
    function test_me()
    {
        alert('Hello World ! This is the my site base url <?php 
echo this()->base;
?>
 ');
        return false;
    }
    

</script>
Exemple #10
0
/**
 * Procedural interface for PHPProto::parent().
 * 
 * @see PHPProto::parent()
 * 
 * @return PHPProto Current prototype object's parent.
 */
function parent()
{
    return this()->parent();
}
 public function gps_data()
 {
     $exif = this($this->extractFromFile('gps-embedded.jpg')->segmentsOf('img.io.ExifSegment'), 0);
     $this->assertEquals(array('Version' => '2/2/0/0', 'Latitude' => '48/1/59/1/54669/1000', 'LatitudeRef' => 'N', 'Longitude' => '8/1/23/1/10003/1000', 'LongitudeRef' => 'E'), array('Version' => $exif->rawData('GPS_IFD_Pointer', 'GPSVersion'), 'Latitude' => $exif->rawData('GPS_IFD_Pointer', 'GPSLatitude'), 'LatitudeRef' => $exif->rawData('GPS_IFD_Pointer', 'GPSLatitudeRef'), 'Longitude' => $exif->rawData('GPS_IFD_Pointer', 'GPSLongitude'), 'LongitudeRef' => $exif->rawData('GPS_IFD_Pointer', 'GPSLongitudeRef')));
 }
 public function namespaced_parameters_handled_correctly()
 {
     $class = $this->proxyClassFor(array(ClassLoader::defineInterface('net.xp_framework.unittest.test.mock.NSInterface', array(), '{
   public function fixture(\\lang\\types\\Long $param);
 }')));
     $this->assertEquals(XPClass::forName('lang.types.Long'), this($class->getMethod('fixture')->getParameters(), 0)->getType());
 }
 /**
  * Retrieve reversed notation
  *
  * @return  string
  */
 public function reversedNotation()
 {
     $nibbles = this(unpack('H*', $this->addr), 1);
     $ret = '';
     for ($i = 31; $i >= 0; $i--) {
         $ret .= $nibbles[$i] . '.';
     }
     return $ret . 'ip6.arpa';
 }
 public function defineClassWithXPClassInterface()
 {
     $interface = \lang\XPClass::forName('lang.Runnable');
     $class = $this->defineClass('_' . $this->name, 'lang.Object', array($interface), '{
   public function run() { }
 }');
     $this->assertEquals($interface, this($class->getDeclaredInterfaces(), 0));
 }
 public function dictionaryInterface()
 {
     $fixture = Type::forName('net.xp_framework.unittest.core.generics.AbstractTypeDictionary<string>');
     $this->assertEquals(array(XPClass::forName('lang.Type'), Primitive::$STRING), this($fixture->getInterfaces(), 1)->genericArguments());
 }
 /**
  * Execute a request
  *
  * @param   var t either a string or a lang.Type - response type, defaults to webservices.rest.RestResponse
  * @param   webservices.rest.RestRequest request
  * @return  webservices.rest.RestResponse
  * @throws  lang.IllegalStateException if no connection is set
  */
 public function execute($t, $request = NULL)
 {
     if (1 === func_num_args()) {
         // Overloaded version with single argument
         $request = $t;
         $type = NULL;
     } else {
         if (is_string($t)) {
             // Overloaded version with string type
             $type = Type::forName($t);
         } else {
             if ($t instanceof Type) {
                 // Overloaded version with Type instance
                 $type = $t;
             } else {
                 throw new IllegalArgumentException('Given type is neither a Type nor a string, ' . xp::typeOf($request) . ' given');
             }
         }
     }
     if (!$request instanceof RestRequest) {
         throw new IllegalArgumentException('Given request is not a RestRequest, ' . xp::typeOf($request) . ' given');
     }
     if (NULL === $this->connection) {
         throw new IllegalStateException('No connection set');
     }
     $send = $this->connection->create(new HttpRequest());
     $send->addHeaders($request->headerList());
     $send->setMethod($request->getMethod());
     $send->setTarget($request->getTarget($this->connection->getUrl()->getPath('/')));
     if ($request->hasBody()) {
         $send->setParameters($request->getBody());
     } else {
         $send->setParameters($request->getParameters());
     }
     try {
         $this->cat && $this->cat->debug('>>>', $send->getRequestString());
         $response = $this->connection->send($send);
     } catch (IOException $e) {
         throw new RestException('Cannot send request', $e);
     }
     if ($type instanceof XPClass && $type->isSubclassOf('webservices.rest.RestResponse')) {
         $rr = $type->newInstance($response, $this->deserializerFor(this($response->header('Content-Type'), 0)));
     } else {
         $rr = new RestResponse($response, $this->deserializerFor(this($response->header('Content-Type'), 0)), $type);
     }
     $this->cat && $this->cat->debug('<<<', $response->toString(), $rr->contentCopy());
     return $rr;
 }
 public function intOffset()
 {
     $this->assertNull(this(0, 0));
 }
echo this()->meta;
?>

<title><?php 
echo this()->title;
?>
</title>

<base href="<?php 
echo this()->base;
?>
" />

<?php 
this()->head .= css('welcome.css');
echo this()->head;
?>

</head>

<body>
<h1>Welcome to Becak MVC Framework</h1>
<?php 
echo this()->body;
?>

<p>Page rendered in {elapsed_time} seconds using {memory_usage} of memory</p>
</body>

</html>
 public function inheritedConstructorsParameters()
 {
     $this->assertEquals(\lang\Primitive::$STRING, this($this->getClass()->getConstructor()->getParameters(), 0)->getType());
 }
 public function gps_data()
 {
     $exif = this($this->extractFromFile('gps-embedded.jpg')->segmentsOf('img.io.ExifSegment'), 0);
     $this->assertEquals(2, $exif->rawData('GPS_IFD_Pointer', 'GPSVersion'));
 }
 /**
  * Execute a request
  *
  * <code>
  *   $client->execute(new RestRequest('/', HttpConstants::GET));
  * </code>
  *
  * @param   var t either a string or a lang.Type - response type, defaults to webservices.rest.RestResponse
  * @param   webservices.rest.RestRequest request
  * @return  webservices.rest.RestResponse
  * @throws  lang.IllegalStateException if no connection is set
  */
 public function execute($t, $request = NULL)
 {
     if (1 === func_num_args()) {
         // Overloaded version with single argument
         $request = $t;
         $type = NULL;
     } else {
         if (is_string($t)) {
             // Overloaded version with string type
             $type = Type::forName($t);
         } else {
             if ($t instanceof Type) {
                 // Overloaded version with Type instance
                 $type = $t;
             } else {
                 throw new IllegalArgumentException('Given type is neither a Type nor a string, ' . xp::typeOf($request) . ' given');
             }
         }
     }
     if (!$request instanceof RestRequest) {
         throw new IllegalArgumentException('Given request is not a RestRequest, ' . xp::typeOf($request) . ' given');
     }
     if (NULL === $this->connection) {
         throw new IllegalStateException('No connection set');
     }
     $send = $this->connection->create(new HttpRequest());
     $send->addHeaders($request->headerList());
     $send->setMethod($request->getMethod());
     $send->setTarget($request->getTarget($this->connection->getUrl()->getPath('/')));
     // Compose body
     // * Serialize payloads using the serializer for the given mimetype
     // * Use bodies as-is, e.g. file uploads
     // * If no body and no payload is set, use parameters
     if ($request->hasPayload()) {
         $send->setParameters(new RequestData($this->serializerFor($request->getContentType())->serialize($this->marshalling->marshal($request->getPayload()))));
     } else {
         if ($request->hasBody()) {
             $send->setParameters($request->getBody());
         } else {
             $send->setParameters($request->getParameters());
         }
     }
     try {
         $this->cat && $this->cat->debug('>>>', $send->getRequestString());
         $response = $this->connection->send($send);
     } catch (IOException $e) {
         throw new RestException('Cannot send request', $e);
     }
     $reader = new ResponseReader($this->deserializerFor(this($response->header('Content-Type'), 0), FALSE), $this->marshalling);
     if (NULL === $type) {
         $rr = new RestResponse($response, $reader);
     } else {
         if ($type instanceof XPClass && $type->isSubclassOf('webservices.rest.RestResponse')) {
             $rr = $type->newInstance($response, $reader);
         } else {
             $rr = new RestResponse($response, $reader, $type);
             // Deprecated!
         }
     }
     $this->cat && $this->cat->debug('<<<', $response->toString(), $rr->contentCopy());
     return $rr;
 }
Exemple #22
0
 /**
  * 
  * @param type $object
  * @return \CityPay\PayPost\PayPostResponse
  * @throws \CityPay\Encoding\ClassNoDeserializable
  */
 public function deserialize($object)
 {
     if (is_object($object)) {
         $array = get_object_vars($object);
     } else {
         if (is_array($object)) {
             $array = $object;
         } else {
             throw new \CityPay\Encoding\ClassNotDeserializable();
         }
     }
     $this->authCode = self::getStringOrException($array, "Authcode");
     $this->authorised = self::getBooleanOrException($array, "Authorised");
     $this->authResult = self::getIntOrException($object, "AuthResult");
     $this->mode = self::getStringOrException($array, "Mode");
     $this->amount = self::getIntOrException($array, "Amount");
     $this->currency = self::getStringOrException($array, "Currency");
     $this->identifier = self::getStringOrException($array, "Identifier");
     $this->code = self::getStringOrException($array, "Code");
     $this->message = self::getStringOrException($array, "Message");
     $this->transNo = self::getIntOrException($array, "TransNo");
     //
     //  Card details
     //
     $this->maskedPan = self::getStringOrException($array, "MaskedPan");
     //
     //  Address verifications
     //
     $this->cscResult = self::getStringOrException($array, "CSCResult");
     $this->avsResult = self::getStringOrException($array, "AVSResult");
     //
     //  Optional 3D Secure-related values
     //
     $this->cavv = self::getStringOrDefault($array, "CAVV");
     $this->eci = self::getStringOrDefault($array, "ECI");
     //
     //  Payload verification
     //
     $this->digest = self::getStringOrException($array, "digest");
     return this();
 }
    ?>
</td>
	<td><?php 
    echo $d['isi'];
    ?>
</td>
	<td><?php 
    echo $d['tgl_posting'];
    ?>
</td>
	<td align="center">
	<a href="<?php 
    echo this()->base_url . '/bukutamu/page/edit/' . $d['id'];
    ?>
">Edit</a> - 
	<a href="<?php 
    echo this()->base_url . '/bukutamu/page/hapus/' . $d['id'];
    ?>
" onclick="return confirm('Anda yakin akan menghapus data ini?')">Hapus</a>
	</td>
</tr>
<?php 
}
//end foreach
?>
</table>
<p>Waktu komputasi {elapsed_time} detik. Kebutuhan memory {memory_usage}</p>
</body>
</html>