示例#1
0
/**
 * Outputs the value of a variable to the PHP error log
 *
 * This function outputs the contents of a variable or object
 * to the PHP error log
 *
 * @see MLog()
 *
 * @param mixed $object The object or variable to output to the
 * error log
 *
 * @return void
 */
function MVarExport($object)
{
    MLog(var_export($object, true));
}
 /**
  * @internal
  *
  * @return void
  */
 protected function enableRouting()
 {
     MLog("[EnableRouting]: Creating '.htaccess' file for URL routing…");
     $fileStream = new MFileOutputStream(new MFile(S(".htaccess")));
     $writer = new MStreamWriter($fileStream);
     $writer->writeLine(S("# Mango URL Routing Code"));
     $writer->writeLine(S("RewriteEngine On"));
     $writer->writeLine(S("RewriteRule . index.php"));
     $writer->close();
     MLog("[EnableRouting]: File created");
 }
 /**
  * @internal
  *
  * @return MArray
  */
 protected function executeFaultRequest(MFaultRequest $request)
 {
     $failedFaults = new MMutableArray();
     foreach ($request->faults()->toArray() as $fault) {
         $data = new MMutableDictionary();
         $relationships = new MMutableDictionary();
         $query = Sf("SELECT * FROM `%s` WHERE `objectID` = :objectID LIMIT 1", $fault->entity()->plural());
         $id = $fault->objectID();
         $statement = $this->connection()->prepare($query->stringValue());
         $statement->bindParam(':objectID', $id, PDO::PARAM_INT);
         $statement->execute();
         $row = $statement->fetch(PDO::FETCH_ASSOC);
         if ($row != null) {
             unset($row['objectID']);
             // Set the object's data
             foreach ($row as $key => $value) {
                 $property = $fault->entity()->attributeWithName(S($key));
                 if ($property) {
                     $boxedValue = null;
                     if ($value != null) {
                         if ($property->type() == MEntityDescriptionProperty::StringType) {
                             $boxedValue = new MString($value);
                         } else {
                             if ($property->type() == MEntityDescriptionProperty::IntegerType) {
                                 $boxedValue = new MNumber($value);
                             } else {
                                 if ($property->type() == MEntityDescriptionProperty::FloatType) {
                                     $boxedValue = new MNumber($value);
                                 } else {
                                     if ($property->type() == MEntityDescriptionProperty::BooleanType) {
                                         $boxedValue = new MNumber($value);
                                     } else {
                                         if ($property->type() == MEntityDescriptionProperty::DateType) {
                                             $boxedValue = MDate::parse($value);
                                         } else {
                                             if ($property->type() == MEntityDescriptionProperty::BinaryType) {
                                                 $boxedValue = new MData($value);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $data->setObjectForKey(S($key), $boxedValue);
                 } else {
                     throw new MPersistentStoreException(S("Database structure incompatible with this model version!"));
                 }
             }
             $fault->_setData($data);
             foreach ($fault->entity()->relationships()->toArray() as $relationship) {
                 $relationshipQuery = Sf("SELECT * FROM `%s` WHERE `%s` = ?;", $relationship->tableName(), $relationship->columnName());
                 $objectID = $fault->objectID();
                 $statement = $this->connection()->prepare($relationshipQuery->stringValue());
                 $statement->bindParam(1, $objectID);
                 $statement->execute();
                 $relationshipObjects = new MMutableArray();
                 foreach ($statement->fetchAll() as $relationshipRow) {
                     $relationshipObject = $this->fetchObjectWithObjectID($this->persistentStoreCoordinator()->model()->entityWithName($relationship->type()), (int) $relationshipRow[$relationship->inverseColumnName()->stringValue()]);
                     if ($relationshipObject) {
                         $relationshipObjects->addObject($relationshipObject);
                     } else {
                         MLog("Warning: Object with ID [%s] is missing from the data store and could not be initialized!", $relationshipRow['objectID']);
                     }
                 }
                 $relationships->setObjectForKey($relationship->name(), $relationshipObjects);
             }
             $fault->_setRelationships($relationships);
         } else {
             $failedFaults->addObject($fault);
         }
     }
     return $failedFaults;
 }