示例#1
0
 /**
  *
  */
 public function renderView($viewCode, $viewContext = null, $viewRoot = null)
 {
     // Fix the view root
     if (empty($viewRoot) === true) {
         $viewRoot = PATH_APP . '/Views';
     }
     // Check whether the view exists
     $pathToView = $viewRoot . '/' . $viewCode;
     if (file_exists($pathToView) === false) {
         \z\e(EXCEPTION_VIEW_NOT_FOUND, ['pathToView' => $pathToView, 'viewCode' => $viewCode, 'viewContext' => $viewContext]);
     }
     // Load the view
     $view = file_get_contents($pathToView);
     // Compile the view
     $code = \LightnCandy\LightnCandy::compile($view, ['basedir' => [PATH_APP . '/Views'], 'fileext' => [''], 'flags' => \LightnCandy\LightnCandy::FLAG_ERROR_EXCEPTION | \LightnCandy\LightnCandy::FLAG_HANDLEBARS | \LightnCandy\LightnCandy::FLAG_RENDER_DEBUG | \LightnCandy\LightnCandy::FLAG_RUNTIMEPARTIAL | \LightnCandy\LightnCandy::FLAG_THIS, 'helpers' => ['locale' => function () {
         return \z\service('manager/culture')->localeCode;
     }, 'str' => function ($indexed, $associative) {
         // Build arguments
         $arguments = $this->buildArguments(['stringCode'], $indexed, $associative);
         // Get the string
         $result = \z\str($arguments['stringCode']);
         return $result;
     }]]);
     // Build path to code
     $pathToCode = '/tmp/' . sha1('fbenard/zero_' . $pathToView) . '.php';
     // Get the view renderer
     file_put_contents($pathToCode, $code);
     $renderer = (require $pathToCode);
     // Render the view
     $result = $renderer($viewContext);
     return $result;
 }
示例#2
0
 /**
  *
  */
 protected function setOutput($output)
 {
     // Encode the output as JSON
     $output = \z\service('factory/json')->encodeJson($output);
     // Set the output
     parent::setOutput($output);
 }
示例#3
0
 /**
  *
  */
 public function getConnection($connectionCode = null)
 {
     // Grab definitions
     $definitions = \z\pref('db/connections');
     if (is_array($definitions) === false) {
         $definitions = [];
     }
     // Define the connection code
     if (empty($connectionCode) === true) {
         $definitions = array_splice($definitions, 0, 1);
         $keys = array_keys($definitions);
         $connectionCode = array_shift($keys);
     }
     // Get the definition
     if (array_key_exists($connectionCode, $definitions) === true) {
         $definition = $definitions[$connectionCode];
     }
     // Check whether there's a definition
     if (empty($definition) === true) {
         \z\e(EXCEPTION_DB_CONNECTION_NOT_FOUND, ['connectionCode' => $connectionCode, 'definitions' => $definitions]);
     }
     // Has the connection been retrieved already?
     if (array_key_exists($connectionCode, $this->_connections) === false) {
         // Build the connection
         $connection = \z\service('factory/connection')->buildConnection($definition);
         // Connect the driver
         $connection->driver->connect($connection);
         // Store the connection
         $this->_connections[$connectionCode] = $connection;
     }
     // Get the connection
     $connection = $this->_connections[$connectionCode];
     return $connection;
 }
示例#4
0
 /**
  *
  */
 public function buildObject($modelCode)
 {
     // Get the model
     $model = \z\service('manager/model')->getModel($modelCode);
     // Build the object
     $object = new \fbenard\Material\Classes\Object($modelCode, array_keys($model['properties']));
     return $object;
 }
示例#5
0
 /**
  *
  */
 public function loadJson($path, $array = true)
 {
     // Load the JSON file
     $json = \z\service('helper/file')->loadFile($path);
     // Load and decode the JSON
     $result = $this->decodeJson($json, $array);
     return $result;
 }
 /**
  *
  */
 public function transform($query, $connector)
 {
     // Prepare the result
     $result = ['CREATE', 'TABLE', \z\service('transformer/mysql/query/create/table')->transform($query->table, $connector), $this->transformEngine($query, $connector), $this->transformCharset($query, $connector)];
     // Build the result
     $result = $this->buildResult($result);
     return $result;
 }
 /**
  *
  */
 private function transformFields($table, $connection)
 {
     //
     $result = [];
     foreach ($table->fields as $field) {
         $result[] = \z\service('transformer/mysql/query/create/field')->transform($field, $connection);
     }
     return $result;
 }
示例#8
0
 /**
  *
  */
 private function runActions($actions)
 {
     // Execute each post action
     foreach ($actions as $action) {
         // Fix the definition
         $action = array_merge(['method' => null, 'service' => null], $action);
         // Call the post action
         call_user_func_array([\z\service($action['service']), $action['method']], $this->_arguments);
     }
 }
示例#9
0
 /**
  *
  */
 public function execute()
 {
     // Build the transformer
     $queryTransformer = \z\service('transformer/' . $this->_connection->system . '/query/' . $this->_type);
     // Transform the query
     $query = $queryTransformer->transform($this, $this->_connection);
     // Execute the query
     $result = $this->_connection->driver->executeQuery($query);
     return $result;
 }
示例#10
0
 /**
  *
  */
 public function indexDocument($indexCode, $indexType, $document, $documentId = null)
 {
     // Build arguments
     $arguments = ['index' => $indexCode, 'type' => $indexType, 'body' => $document];
     // Add the document ID to arguments
     if (empty($documentId) === false) {
         $arguments['id'] = $documentId;
     }
     // Index the document
     \z\service('driver/db/es')->index($arguments);
 }
示例#11
0
 /**
  *
  */
 public function initialize()
 {
     // Get dependencies
     $dependencies = \z\boot()->dependencies;
     // Parse each dependency
     foreach ($dependencies as $dependency) {
         // List constants of dependency
         $files = \z\service('helper/file')->listFiles($dependency . '/Constants', 'php');
         // Parse each file
         foreach ($files as $file) {
             // Execute the file
             require_once $file;
         }
     }
 }
示例#12
0
 /**
  *
  */
 public function getLogger($loggerCode = null, $handlers = null)
 {
     // Use the default channel if none provided
     if (empty($loggerCode) === true) {
         $loggerCode = 'app';
     }
     // Does the logger exist?
     if (array_key_exists($loggerCode, $this->_loggers) === false) {
         // Build the logger
         $logger = \z\service('factory/logger')->buildLogger($loggerCode, $handlers);
         // Store the logger
         $this->_loggers[$loggerCode] = $logger;
     }
     // Get the logger
     $logger = $this->_loggers[$loggerCode];
     return $logger;
 }
示例#13
0
 /**
  *
  */
 public function buildConnection($definition)
 {
     // Fix the definition
     $definition = $this->fixDefinition($definition);
     // Build a connection
     $connection = new \fbenard\Material\Classes\Connection();
     // Store the definition
     $connection->charset = $definition['charset'];
     $connection->host = $definition['host'];
     $connection->login = $definition['login'];
     $connection->password = $definition['password'];
     $connection->name = $definition['name'];
     $connection->system = $definition['system'];
     // Build the driver
     $connection->driver = \z\service('driver/db/' . $connection->system, true);
     return $connection;
 }
示例#14
0
 /**
  *
  */
 private function loadPreferences()
 {
     // Get the cache
     $cacheCode = 'preferences_' . \z\boot()->environment;
     $cache = \z\cache()->getCache($cacheCode);
     if ($cache !== false) {
         $this->_preferences = unserialize($cache);
         return;
     }
     // Define the number of passes
     $dependencies = \z\boot()->dependencies;
     $nbPasses = count($dependencies) - 1;
     // Perform n passes
     for ($i = 0; $i < $nbPasses; $i++) {
         foreach ($dependencies as $dependency) {
             // List preferences
             $paths = array_merge(\z\service('helper/file')->listFiles($dependency . '/Config/Preferences', 'json'), \z\service('helper/file')->listFiles($dependency . '/Config/Preferences/' . \z\boot()->environment, 'json'));
             // Parse each path
             foreach ($paths as $path) {
                 // Build the preference code
                 $parentPreferenceCode = strtolower(basename($path, '.json'));
                 // Load preferences
                 $preferences = \z\service('factory/json')->loadJson($path);
                 // Store preferences
                 foreach ($preferences as $preferenceCode => $preferenceValue) {
                     // Build the new preference code
                     $preferenceCode = $parentPreferenceCode . '/' . $preferenceCode;
                     // Get the previous preference value
                     $oldPreferenceValue = \z\pref($preferenceCode);
                     // Is it an array?
                     if (is_array($oldPreferenceValue) === true) {
                         // Merge the old + the new
                         $preferenceValue = array_merge($oldPreferenceValue, $preferenceValue);
                     }
                     // Set the preference
                     \z\pref($preferenceCode, $preferenceValue);
                 }
             }
         }
         // End of pass, remove the first extension
         array_shift($dependencies);
     }
     // Set the cache
     \z\cache()->setCache($cacheCode, serialize($this->_preferences));
 }
示例#15
0
 /**
  *
  */
 private function loadDefinitions()
 {
     // Get the cache
     $cacheCode = 'routes_' . \z\boot()->environment;
     $cache = \z\cache()->getCache($cacheCode);
     if ($cache !== false) {
         $this->_definitions = unserialize($cache);
         return;
     }
     //
     $dependencies = \z\boot()->dependencies;
     //
     foreach ($dependencies as $dependency) {
         // Find definitions
         $paths = \z\service('helper/file')->listFiles($dependency . '/Config/Routes', 'json', true);
         // For each definitions
         foreach ($paths as $path) {
             // Load definitions
             $rawDefinitions = file_get_contents($path);
             $definitions = json_decode($rawDefinitions, true);
             // Make sure definitions is an array
             if (is_array($definitions) === false) {
                 continue;
             }
             // For each definition
             foreach ($definitions as &$definition) {
                 // Make sure the definition is valid
                 $definition = array_merge(['arguments' => [], 'verbs' => [], 'post' => [], 'pre' => []], $definition);
                 // For each verb
                 foreach ($definition['verbs'] as &$verb) {
                     // Make sure the verb is valid
                     $verb = array_merge(['action' => 'index', 'controller' => null], $verb);
                 }
             }
             // Store definitions
             $this->_definitions = array_merge($this->_definitions, $definitions);
         }
     }
     // Set the cache
     \z\cache()->setCache($cacheCode, serialize($this->_definitions));
 }
示例#16
0
 /**
  *
  */
 private function loadConfig()
 {
     // Get the cache
     $cacheCode = 'events_' . \z\boot()->environment;
     $cache = \z\cache()->getCache($cacheCode);
     if ($cache !== false) {
         $this->_followers = unserialize($cache);
         return;
     }
     // Parse each dependency
     $dependencies = \z\boot()->dependencies;
     foreach ($dependencies as $dependency) {
         //
         $paths = \z\service('helper/file')->listFiles($dependency . '/Config/Events', 'php');
         foreach ($paths as $path) {
             require_once $path;
         }
     }
     // Set the cache
     \z\cache()->setCache($cacheCode, serialize($this->_followers));
 }
示例#17
0
 /**
  *
  */
 public function set($propertyCode, $propertyValue)
 {
     return \z\service('manager/object')->setObjectProperty($this, $propertyCode, $propertyValue);
 }
示例#18
0
 /**
  *
  */
 public function __call($methodCode, $methodArguments)
 {
     return \z\service('query/' . $methodCode, true);
 }
示例#19
0
 /**
  *
  */
 public function buildDocument($modelCode, $object)
 {
     // Build result
     $result = [];
     // Get the model
     $model = \z\service('manager/model')->getModel($modelCode);
     // Parse each property
     foreach ($model['properties'] as $propertyCode => $property) {
         // Get the property value
         $propertyValue = $object->get($propertyCode);
         // Temporary hack
         if ($property['type'] === 'datetime') {
             //
             if ($propertyValue === '0000-00-00 00:00:00') {
                 $propertyValue = null;
             }
             //
             if (empty($propertyValue) === false) {
                 //
                 $date = new \DateTime($propertyValue);
                 $propertyValue = $date->format('Y-m-d') . 'T' . $date->format('H:i:s');
             }
         }
         // Is it a relation?
         if (\z\service('helper/object/property')->isRelation($property) === true) {
             // Is it a 0:1 or a 0:n relation?
             if (\z\service('helper/object/property')->is01Relation($property) === true) {
                 // Build the relation
                 $relation = \z\service('factory/object')->buildObject($property['model']);
                 // Load the relation
                 $relation->load($propertyValue);
                 // Export the relation
                 $propertyValue = $relation->export(false);
             } else {
                 if (\z\service('helper/object/property')->is0NRelation($property) === true) {
                     // Decode sub-property values
                     $subPropertyValues = json_decode($propertyValue, true);
                     // Parse each sub-property value
                     $relations = [];
                     if (is_array($subPropertyValues) === true) {
                         foreach ($subPropertyValues as $subPropertyValue) {
                             // Build the relation
                             $relation = \z\service('factory/object')->buildObject($property['model']);
                             // Load the relation
                             $relation->load($subPropertyValue);
                             // Export the relation
                             $relations[] = $relation->export(false);
                         }
                     }
                     // Have we found any relation?
                     if (empty($relations) === true) {
                         $propertyValue = new \stdClass();
                     } else {
                         $propertyValue = $relations;
                     }
                 }
             }
         }
         // Store the property
         $result[$propertyCode] = $propertyValue;
     }
     return $result;
 }
示例#20
0
 /**
  *
  */
 public function run()
 {
     // Initialize the application
     $this->initialize();
     // Run the controller manager
     \z\service('manager/controller')->run();
     // Quit the application
     $this->quit();
 }
示例#21
0
/**
 *
 */
function unfollow($eventCode, $followerCode)
{
    return \z\service('manager/event')->removeFollower($eventCode, $followerCode);
}
示例#22
0
 /**
  *
  */
 public function actionMigrationApply($from = null, $to = null)
 {
     \z\service('manager/migration')->applyMigration($from, $to);
 }
示例#23
0
 /**
  *
  */
 private function storeSearch($search)
 {
     //
     unset($search[5]);
     unset($search[6]);
     //
     $search = json_encode($search);
     $searchId = md5($search);
     // Store the search
     \z\service('driver/redis')->set($searchId, $search);
     return $searchId;
 }
示例#24
0
 /**
  *
  */
 private function loadStrings()
 {
     // Get the cache
     $cacheCode = 'strings_' . $this->_localeCode . '_' . $this->_fallbackCode;
     $cache = \z\cache()->getCache($cacheCode);
     if ($cache !== false) {
         $this->_strings = unserialize($cache);
         return;
     }
     // Build locales
     $locales = [$this->_localeCode, $this->_fallbackCode];
     // Parse each locale
     foreach ($locales as $localeCode) {
         // Build an array for the locale
         $this->_strings[$localeCode] = [];
         // List string files for this locale
         $paths = \z\service('helper/file')->listFiles(PATH_APP . '/Config/Strings/' . $localeCode, 'json');
         // Parse each string file
         foreach ($paths as $path) {
             // Load the string file
             $rawStrings = file_get_contents($path);
             $strings = json_decode($rawStrings, true);
             // Store the strings
             $this->_strings[$localeCode] = array_merge($this->_strings[$localeCode], $strings);
         }
     }
     // Set the cache
     \z\cache()->setCache($cacheCode, serialize($this->_strings));
 }
示例#25
0
 /**
  *
  */
 public function deleteAllIndexes()
 {
     \z\service('driver/db/es')->indices()->delete(['index' => '_all']);
 }
示例#26
0
 /**
  *
  */
 protected function renderView($viewCode, $viewContext = null, $viewRoot = null)
 {
     $this->setOutput(\z\service('renderer/view')->renderView($viewCode, $viewContext, $viewRoot));
 }
示例#27
0
 /**
  *
  */
 public function scrollModel($modelCode, $page = null, $pageSize = null)
 {
     // Define the page size
     if (empty($pageSize) === true) {
         $pageSize = \z\pref('page/size');
     }
     // Select inputs within the page boundary
     $inputs = \z\service('factory/query')->select()->from($modelCode)->offset($page * $pageSize)->limit($pageSize)->execute();
     // Parse each input
     $result = [];
     foreach ($inputs as $input) {
         // Build an object
         $object = \z\service('factory/object')->buildObject($modelCode);
         // Import the input
         $object->import($input);
         // Store the object
         $result[] = $object;
     }
     return $result;
 }