/**
  * 
  *
  * @return MNumberOutOfRangeException
  */
 public function __construct(MNumber $number, MNumber $lowerBound, MNumber $upperBound, MException $previous = null)
 {
     parent::__construct(Sf("Number [%s] out of range [%s-%s]", $number->toString()->stringValue(), $lowerBound->toString()->stringValue(), $upperBound->toString()->stringValue()), MException::NUMBER_OUT_OF_RANGE_EXCEPTION_CODE, $previous);
     $this->number = $number;
     $this->lowerBound = $lowerBound;
     $this->upperBound = $upperBound;
 }
 /**
  * Creates a new instance of MManagedObjectException
  *
  * @param MManagedObject $object The Managed Object that cause the exception to be raised
  * @param MString|null $object The description of the error
  * @param MException|null $previous The previous exception that caused this exception to
  * be raised
  *
  * @return MManagedObjectException The new exception instance
  */
 public function __construct(MManagedObject $object, MString $description = null, MException $previous = null)
 {
     if ($description == null) {
         $description = S("Unknown Managed Object Error");
     }
     $description = Sf("%s [%s]", $description, $object);
     parent::__construct($description, MException::MANAGED_OBJECT_EXCEPTION_CODE, $previous);
 }
 /**
  * 
  */
 public function setElement(MString $element)
 {
     if ($element->equals(S("p"))) {
         parent::setElement($element);
     } else {
         throw new MException(Sf("Invalid element '%s', must be paragraph 'p'", $element));
     }
 }
 /**
  * 
  *
  * @return MIndexOutOfBoundsException
  */
 public function __construct($index = 0, $lowerBound = 0, $upperBound = 0, MException $previous = null)
 {
     MAssertTypes('int', $index, 'int', $lowerBound, 'int', $upperBound);
     parent::__construct(Sf("Index [%d] out of bounds [%d -> %d]", $index, $lowerBound, $upperBound), MException::NUMBER_OUT_OF_RANGE_EXCEPTION_CODE, $previous);
     $this->index = $index;
     $this->lowerBound = $lowerBound;
     $this->upperBound = $upperBound;
 }
 public function loadView()
 {
     parent::loadView();
     if (!$this->documentView) {
         $this->documentView = new MHTMLDocumentView();
         $this->documentView->addSubview(new MHTMLHeaderElementView(Sf("Welcome to Mango-Framework!")));
         $this->setView($this->documentView);
     }
 }
 /**
  * Initializes a new instance of MInvalidManagedObjectOperationException
  *
  * This exception is thrown when an invalid operation is performed on a MManagedObject instance
  */
 public function __construct(MManagedObject $object, MString $description = null, MException $previous = null)
 {
     if ($description == null) {
         $description = S("Invalid Managed Object Operation Error");
     }
     $description = Sf("%s [%s]", $description, $object);
     parent::__construct($description, $previous);
     $this->object = $object;
 }
 /**
  * Creates a new model parse error exception instance
  *
  * @param MFile $modelFile The file that caused the parse error
  * @param MString|null $description The description of the error
  * @param MException|null $previous The previous exception that cause this error to
  * happen
  *
  * @return MModelParseErrorException The new exception instance
  */
 public function __construct(MFile $modelFile, MString $description = null, MException $previous = null)
 {
     $d = $description;
     if ($d == null) {
         $d = Sf("Model Parse Error on file [%s]", $modelFile->path()->stringValue());
     } else {
         $d = $d->stringByAppendingString(Sf("\nModel file: [%s]", $modelFile->path()->stringValue()));
     }
     parent::__construct($d, MException::MODEL_PARSE_ERROR_EXCEPTION_CODE, $previous);
     $this->modelFile = $modelFile;
 }
 /**
  *
  * @param $namespaceElement
  *
  * @return MApplicationNamespace
  */
 public static function parseFromXMLElement($namespaceElement, $name = null)
 {
     $namespaceName = $name;
     if (is_null($namespaceName)) {
         $namespaceName = S($namespaceElement['name']);
     }
     $namespace = new MApplicationNamespace($namespaceName);
     foreach ($namespaceElement as $element) {
         if ($element->getName() == "controller") {
             $namespace->addChildNode(MApplicationController::parseFromXMLElement($element));
         } else {
             if ($element->getName() == "namespace") {
                 $namespace->addChildNode(MApplicationNamespace::parseFromXMLElement($element));
             } else {
                 throw new MParseErrorException(null, null, Sf("Unknown element '%s'", $element->getName()));
             }
         }
     }
     return $namespace;
 }
 /**
  * 
  *
  * @return MNaNException
  */
 public function __construct($value, MException $parent = null)
 {
     parent::__construct(Sf("Value (%s) is not a number!", $value), MException::NAN_EXCEPTION_CODE, $parent);
 }
 /**
  * 
  *
  * @return MView
  */
 public function view()
 {
     if ($this->applicationController()) {
         if ($this->applicationController()->acceptsMethod(S(MHTTPRequest()->method()))) {
             if (MHTTPRequest()->contentType()) {
                 $contentTypes = MHTTPRequest()->contentType()->componentsSeparatedByString(S(";"));
                 foreach ($contentTypes->toArray() as $contentType) {
                     $type = $contentType->stringByTrimmingEmptySpaces();
                     if ($this->applicationController()->acceptedMethodForMethod(S(MHTTPRequest()->method()))->contentTypes()->count() > 0) {
                         if (!$this->applicationController()->acceptedMethodForMethod(S(MHTTPRequest()->method()))->contentTypes()->containsObject($type)) {
                             throw new MBadRequestException(Sf("The specified content-type (%s) is not supported", $type));
                         }
                     }
                 }
             }
             if ($this->isRestricted()) {
                 if (!$this->authenticatedUserName) {
                     $authenticateHeader = Sf('Digest realm="%s", qop="auth", nonce="%s", opaque="%s"', $this->realm(), uniqid(), md5($this->realm()));
                     if (empty(MHTTPRequest::request()->server()['PHP_AUTH_DIGEST'])) {
                         $this->setResponseCode(MHTTPResponse::RESPONSE_UNAUTHORIZED);
                         $this->addResponseHeader(S("WWW-Authenticate"), $authenticateHeader);
                         return $this->accessDeniedView();
                     } else {
                         $data = $this->_parseDigest(MHTTPRequest::request()->server()['PHP_AUTH_DIGEST']);
                         $username = $data->objectForKey(S("username"));
                         if ($username) {
                             $password = $this->passwordForUserWithName($username);
                             if ($password) {
                                 $A1 = S(md5(Sf("%s:%s:%s", $data->objectForKey(S("username")), $this->realm(), $password)));
                                 $A2 = S(md5(Sf("%s:%s", MHTTPRequest::request()->server()['REQUEST_METHOD'], $data->objectForKey(S("uri")))));
                                 $validResponse = S(md5(Sf("%s:%s:%s:%s:%s:%s", $A1, $data->objectForKey("nonce"), $data->objectForKey("nc"), $data->objectForKey("cnonce"), $data->objectForKey("qop"), $A2)));
                                 if ($data->objectForKey("response")->equals($validResponse)) {
                                     $this->authenticatedUserName = $username;
                                     return $this->_view();
                                 } else {
                                     $this->setResponseCode(MHTTPResponse::RESPONSE_UNAUTHORIZED);
                                     $this->addResponseHeader(S("WWW-Authenticate"), $authenticateHeader);
                                     return $this->invalidCredentialsView();
                                 }
                             } else {
                                 $this->setResponseCode(MHTTPResponse::RESPONSE_UNAUTHORIZED);
                                 $this->addResponseHeader(S("WWW-Authenticate"), $authenticateHeader);
                                 return $this->invalidCredentialsView();
                             }
                         } else {
                             $this->setResponseCode(MHTTPResponse::RESPONSE_UNAUTHORIZED);
                             $this->addResponseHeader(S("WWW-Authenticate"), $authenticateHeader);
                             return $this->invalidCredentialsView();
                         }
                     }
                 } else {
                     return $this->_view();
                 }
             } else {
                 return $this->_view();
             }
         } else {
             throw new MBadRequestException(Sf("The specified request method (%s) is not supported", MHTTPRequest()->method()));
         }
     } else {
         return $this->_view();
     }
 }
Example #11
0
 /**
  * 
  *
  * @return MString
  */
 public function stringByAppendingPathComponent(MString $component)
 {
     $pathSeparator = S("");
     if (!$this->endsWith(S("/"))) {
         $pathSeparator = S("/");
     }
     return $this->stringByAppendingString(Sf("%s%s", $pathSeparator, $component));
 }
 /**
  * 
  */
 public function toString()
 {
     return Sf("[MManagedObject=>%s <%s>]", $this->className(), $this->hash());
 }
Example #13
0
function Sl($file = false, $layout = 'layout.html.php')
{
    if ($file) {
        SometimesData::set('_layout', Sf($file));
        return Sf($layout);
    } else {
        return SometimesData::get('_layout');
    }
}
Example #14
0
<?php

Sd('title', 'Signup');
switch (Sd('create')) {
    case '1':
        Sd('error', 'Usernames must be between 4 and 40 characters.');
        break;
    case '2':
        Sd('error', 'Please confirm your password.');
        break;
    case '3':
        Sd('error', 'Passwords must be between 4 and 40 characters.');
        break;
    case '4':
        Sd('error', 'Something went wrong here.&nbsp; Are you sure you&rsquo;re not already registered?');
        break;
}
return Snil(Sf('_signup.html.php'), p('Already have an account?&nbsp; ', a(array('href' => '/start#login'), 'Login')));
 /**
  * Returns a Managed Object whose property matches the specified object value
  *
  * This method fetches an object from the Persistent Store that contains the
  * specified property and whose value for that property matches the value
  * specified in $value
  *
  * @param MEntityDescriptionProperty $property The property whose value you
  * wish to match against
  * @param MObject $value The value to be matched
  *
  * @return MManagedObject The fetched MManagedObject
  */
 public function objectWith(MEntityDescriptionProperty $property, MObject $value = null)
 {
     $request = new MFetchRequest($property->entity(), $this);
     if ($value) {
         $request->setPredicate(Sf("%s = '%s'", $property->name()->stringValue(), $value->toString()->stringValue()));
     } else {
         $request->setPredicate(Sf("%s = null", $property->name()->stringValue()));
     }
     $data = $this->executeFetchRequest($request);
     return $data->lastObject();
 }
 /**
  * @internal
  *
  * Used internally to parse the Model from it's model file
  *
  * @return void
  */
 protected function parse()
 {
     $xmlModels = simplexml_load_file($this->modelFile()->path()->stringValue());
     if (!$this->version()) {
         $this->version = S((string) $xmlModels->{'current-version'});
     }
     $model = null;
     foreach ($xmlModels->model as $m) {
         if (S((string) $m['version'])->equals($this->version())) {
             $model = $m;
         }
     }
     if ($model != null) {
         $relationshipsToLink = new MMutableDictionary();
         foreach ($model->entity as $entity) {
             $newEntity = new MEntityDescription(S((string) $entity['name']), S((string) $entity['plural']), S((string) $entity['class']));
             foreach ($entity->property as $property) {
                 $newProperty = new MEntityDescriptionProperty($newEntity, S((string) $property['name']));
                 if ((string) $property['type'] != null) {
                     $newProperty->setType((string) $property['type']);
                 }
                 if ((string) $property['defaultValue'] != null) {
                     $defaultValue = null;
                     if ($newProperty->type() == MEntityDescriptionProperty::StringType) {
                         $defaultValue = new MString((string) $property['defaultValue']);
                     } else {
                         if ($newProperty->type() == MEntityDescriptionProperty::IntegerType) {
                             $defaultValue = MNumber::parseInt((string) $property['defaultValue']);
                         } else {
                             if ($newProperty->type() == MEntityDescriptionProperty::FloatType) {
                                 $defaultValue = MNumber::parseFloat((string) $property['defaultValue']);
                             } else {
                                 if ($newProperty->type() == MEntityDescriptionProperty::BooleanType) {
                                     $defaultValue = MNumber::parseBool((string) $property['defaultValue']);
                                 } else {
                                     if ($newProperty->type() == MEntityDescriptionProperty::DateType) {
                                         $defaultValue = MDate::parseString((string) $property['defaultValue']);
                                     } else {
                                         if ($newProperty->type() == MEntityDescriptionProperty::BinaryType) {
                                             // BinaryType's defaultValue is ignored, always null
                                         } else {
                                             throw new MModelParseErrorException($this->modelFile(), Sf("Invalid data type '%s'", $newProperty->type()));
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $newProperty->setDefaultValue($defaultValue);
                 }
             }
             foreach ($entity->relationship as $relationship) {
                 $newRelationship = new MEntityDescriptionRelationship($newEntity, S((string) $relationship['name']), S((string) $relationship['type']));
                 $newRelationship->setSingular(S((string) $relationship['singular']));
                 if (strtolower((string) $relationship['to']) == "many") {
                     $newRelationship->setTo(MEntityDescriptionRelationship::ToMany);
                 } else {
                     $newRelationship->setTo(MEntityDescriptionRelationship::ToOne);
                 }
                 if ($relationship['inverse'] != null) {
                     $relationshipsToLink->setObjectForKey($newRelationship, S((string) $relationship['inverse']));
                 }
             }
             $this->addEntity($newEntity);
         }
         // Link relationships to their respective inverse relationships
         foreach ($relationshipsToLink->allKeys()->toArray() as $relationship) {
             $inverse = $relationshipsToLink->objectForKey($relationship);
             $inverseEntity = $this->entityWithName($relationship->type());
             if ($inverseEntity) {
                 $inverseRelationship = $inverseEntity->attributeWithName($inverse);
                 if ($inverseRelationship) {
                     $relationship->setInverseRelationship($inverseRelationship);
                 } else {
                     throw new MModelParseErrorException($this->modelFile(), Sf("Could not find the relationship named '%s' in entity '%s'", $inverse, $relationship->type()));
                 }
             } else {
                 throw new MModelParseErrorException($this->modelFile(), Sf("[%s->%s] Inverse relationship's entity named '%s' not defined in this model version", $relationship->entity()->name(), $relationship->name(), $relationship->type()));
             }
         }
     } else {
         throw new MModelVersionNotFoundException($this->modelFile());
     }
 }
 /**
  * @internal
  *
  * @return MHTTPRequest
  */
 public function __construct($simulatedRequestFile = null, $simulatedRequestName = null)
 {
     parent::__construct();
     $this->method = null;
     $this->contentType = null;
     $this->contents = null;
     $this->inputParameters = null;
     $this->inputFields = null;
     $this->arguments = null;
     $this->baseAddress = null;
     $this->relativeAddress = null;
     $this->baseUrl = null;
     $this->url = null;
     if ($simulatedRequestFile) {
         if (file_exists($simulatedRequestFile)) {
             $json = json_decode(file_get_contents($simulatedRequestFile), true);
             if (!empty($simulatedRequestName)) {
                 $request = $json[$simulatedRequestName];
                 if (!empty($request)) {
                     $this->server = array_merge($_SERVER, $json[$simulatedRequestName]['server']);
                     $this->get = array_merge($_GET, $json[$simulatedRequestName]['get']);
                     $this->post = array_merge($_POST, $json[$simulatedRequestName]['post']);
                     $this->contentsFile = $json[$simulatedRequestName]['contents-file'];
                 } else {
                     throw new Exception(Sf("Could not find request named '%s' inside '%s'", $simulatedRequestName, $simulatedRequestFile));
                 }
             } else {
                 throw new MException(S("You must specify a 'request_name'. Usage: hhvm -m index.php --simulated-request [json_request_file] [request_name]"));
             }
         } else {
             throw new MFileNotFoundException(S($simulatedRequestFile));
         }
     } else {
         $this->server = $_SERVER;
         $this->get = $_GET;
         $this->post = $_POST;
         $this->contentsFile = "php://input";
     }
 }
 /**
  * @internal
  *
  * Returns the table name for this relationship
  *
  * This method returns the low level table name to be used with the database.
  * This method should be used only internally to determine the details of the
  * data storage. The table name is the result of the entity name combined with
  * the inverse relationship's entity name, combined with both, this relationship's
  * name and the inverse relationship's name. The resulting string is then hashed
  * and an MD5 hash is used. This ensures that no two relationships have the same
  * table name.
  *
  * @return MString A String containg the table name for this relationship
  */
 public function tableName()
 {
     $names = A($this->entity()->name(), $this->inverseRelationship()->entity()->name(), $this->name(), $this->inverseRelationship()->name())->sortedArray(MArray::ORDER_ASCENDING, SORT_STRING);
     return Sf("Z_%s", S(md5($names->componentsJoinedByString(S(""))))->substringToIndex(16)->toUpper());
 }
 /**
  * Execute a request across all persistent stores and returns the results
  * if any
  *
  * @param MPersistentStoreRequest $request The request to be peformed
  *
  * @return MArray|null An Array containing the results for the request
  * or null if the request yields no results
  */
 public function executeRequest(MPersistentStoreRequest $request)
 {
     if ($this->persistentStores()->count() > 0) {
         if ($request->requestType() == MPersistentStoreRequest::SaveRequestType) {
             $objects = new MArray();
             foreach ($this->persistentStores()->toArray() as $persistentStore) {
                 $objects = $persistentStore->executeRequest($request);
             }
             return $objects;
         } else {
             if ($request->requestType() == MPersistentStoreRequest::FetchRequestType) {
                 return $this->persistentStores()->anyObject()->executeRequest($request);
             } else {
                 if ($request->requestType() == MPersistentStoreRequest::FaultRequestType) {
                     return $this->persistentStores()->anyObject()->executeRequest($request);
                 } else {
                     throw new MPersistentStoreException(Sf("Unsupported request type (%s)", $request->requestType()));
                 }
             }
         }
     } else {
         throw new MPersistentStoreException(S("No persistent stores defined!"));
     }
 }
 public function __construct(MString $parameterName, MException $previous = null)
 {
     parent::__construct(Sf("Parameter named '%s' undefined", $parameterName), MException::PARAMETER_UNDEFINED_EXCEPTION, $previous);
     $this->parameterName = $parameterName;
 }
 /**
  *
  */
 public function toString()
 {
     return Sf("%s(%s)", $this->className(), $this->name());
 }
 public function __construct(MString $filePath, MException $previous = null)
 {
     parent::__construct(Sf("File at path '%s' could not be found!", $filePath), MException::FILE_NOT_FOUND_EXCEPTION, $previous);
     $this->filePath = $filePath;
 }
 public function __construct(MString $fieldName, MException $previous = null)
 {
     parent::__construct(Sf("Field named '%s' undefined", $fieldName), MException::FIELD_UNDEFINED_EXCEPTION, $previous);
     $this->fieldName = $fieldName;
 }
 /**
  * 
  *
  * @return MInvalidDataTypeException
  */
 public function __construct(MString $expected, MString $given, MException $previous = null)
 {
     parent::__construct(Sf("Invalid data type exception. Expecting %s but %s was given!", $expected, $given), MException::INVALID_DATA_TYPE_EXCEPTION_CODE, $previous);
     $this->expected = $expected;
     $this->given = $given;
 }
 /**
  * 
  *
  * @return MString
  */
 public function toString()
 {
     if ($this->element()) {
         $markup = new MMutableString();
         $indentString = MString::stringWithRepeatingString(S(" "), $this->indentLevel());
         $properties = new MMutableArray();
         foreach ($this->properties()->allKeys()->toArray() as $name) {
             $value = $this->properties()->objectForKey($name);
             $properties->addObject(Sf("%s=\"%s\"", $name, $value));
         }
         if ($properties->count() > 0) {
             $markup->appendFormat("%s<%s %s", $indentString, $this->element(), $properties->componentsJoinedByString(S(" ")));
         } else {
             $markup->appendFormat("%s<%s", $indentString, $this->element());
         }
         if ($this->text()) {
             $markup->appendFormat(">%s</%s>", $this->text()->stringByEncodingHTMLEntities(), $this->element());
         } else {
             if ($this->subviews()->count() > 0) {
                 $markup->appendLine(S(">"));
                 $markup->appendLine(parent::toString());
                 $markup->appendString(Sf("%s</%s>", $indentString, $this->element()));
             } else {
                 $markup->appendString(S("/>"));
             }
         }
         if ($this->shouldAppendEmptyLine()) {
             $markup->appendLine();
         }
         return $markup;
     } else {
         return parent::toString();
     }
 }
 /**
  * Contructs a new XML Managed Object View that represents the object specified in
  * XML format
  *
  * @param MManagedObject $managedObject The Managed Object to be represented as
  * an XML Element View
  *
  * @return MXMLManagedObjectView The new XML Element View instance
  */
 public function __construct(MManagedObject $managedObject)
 {
     parent::__construct($managedObject->entity()->name());
     $this->managedObject = $managedObject;
     $this->dynamicFields = new MMutableDictionary();
     $this->dynamicFieldViews = new MMutableDictionary();
     $this->setValueForProperty(S("objectID"), S((string) $this->managedObject()->objectID()));
     if (!$managedObject->isFault()) {
         foreach ($managedObject->entity()->attributes()->toArray() as $attribute) {
             if ($attribute instanceof MEntityDescriptionProperty) {
                 $object = $managedObject->objectForAttribute($attribute);
                 $propertyElement = new MXMLElementView($attribute->name(), $object ? $object->toString() : S(""));
                 $propertyElement->setValueForProperty(S("type"), S($attribute->type()));
                 $this->addSubview($propertyElement);
             } else {
                 if ($attribute instanceof MEntityDescriptionRelationship) {
                     $relationshipElement = new MXMLElementView($attribute->name());
                     $relationshipElement->setValueForProperty(S("type"), $attribute->type());
                     $relationshipValues = $managedObject->objectForAttribute($attribute);
                     if (!$relationshipValues instanceof MArray) {
                         $relationshipValues = A(array($relationshipValues));
                     }
                     foreach ($relationshipValues->toArray() as $object) {
                         $objectElement = new MXMLElementView($attribute->singular());
                         $objectElement->setValueForProperty(S("objectID"), Sf("%d", $object->objectID()));
                         $relationshipElement->addSubview($objectElement);
                     }
                 } else {
                     throw new MManagedObjectException($managedObject, S("Unsupported Attribute Type"));
                 }
             }
         }
     }
 }
 /**
  * 
  *
  * @return MMethodNotSupportedException
  */
 public function __construct(MString $method = null, MException $previous = null)
 {
     parent::__construct(Sf("Method not supported ['%s']", $method), MException::METHOD_NOT_SUPPORTED_EXCEPTION_CODE, $previous);
 }
Example #28
0
 /**
  *
  */
 public function fullClassName()
 {
     return Sf("%s.%s", $this->packageName(), $this->className());
 }
 /**
  * 
  */
 public function element()
 {
     return Sf("h%d", $this->headerType);
 }
Example #30
0
<?php

Sd('title', 'Login');
Sd('error', 'Something went wrong.&nbsp; Are you sure that&rsquo;s your password?');
return Snil(Sf('_login.html.php'), p('Need to create an account?&nbsp; ', a(array('href' => '/start#signup'), 'Signup')));