Пример #1
0
 /**
  * @param $temporary_file_name string
  */
 public function __construct($temporary_file_name = null)
 {
     if (isset($temporary_file_name)) {
         if (!isset($this->name)) {
             $this->name = rLastParse($temporary_file_name, SL, 1, true);
         }
         $this->temporary_file_name = $temporary_file_name;
     }
     if (!isset($this->updated_on)) {
         $this->updated_on = Builder::create(Date_Time::class);
     }
 }
Пример #2
0
 /**
  * @param $property Reflection_Property
  * @param $value    mixed
  * @param $preprop  string
  */
 public function __construct(Reflection_Property $property = null, $value = null, $preprop = null)
 {
     if (isset($property)) {
         $name = $property->pathAsField();
         if (strpos($name, '[')) {
             $preprop2 = lLastParse($name, '[');
             $preprop = $preprop ? $preprop . '[' . lParse($preprop2, '[') . '[' . rParse($preprop2, '[') : $preprop2;
             $name = lParse(rLastParse($name, '['), ']');
         }
         parent::__construct($name, $property->getType(), $value, $preprop);
         $this->null = $property->getAnnotation('null')->value;
         $this->property = $property;
         $this->readonly = $property->getListAnnotation('user')->has(User_Annotation::READONLY);
     } else {
         parent::__construct(null, null, $value, $preprop);
     }
 }
Пример #3
0
 /**
  * Returns the Dao function as SQL
  *
  * @param $builder       Builder\Where the sql query builder
  * @param $property_path string the property path
  * @param $prefix        string
  * @return string
  */
 public function toSql(Builder\Where $builder, $property_path, $prefix = '')
 {
     $joins = $builder->getJoins();
     // sub-query
     $class_name = $joins->getStartingClassName();
     $properties = $this->properties + [$property_path => Func::max()];
     $sub_builder = new Builder\Select($class_name, $properties, null, $builder->getSqlLink(), [Dao::groupBy($this->properties)]);
     // join
     $join = new Subquery($sub_builder);
     $joins->addJoin($join);
     // where
     $where = '';
     foreach (array_merge($this->properties, [$property_path]) as $property) {
         $where .= ' AND ' . $join->foreign_alias . DOT . BQ . rLastParse($property, DOT, 1, true) . BQ . ' = ' . $builder->buildColumn($property, $prefix);
     }
     $join->where = substr($where, 5);
     return null;
 }
Пример #4
0
 /**
  * Replace URI with correct URI path
  *
  * @param $uri string
  * @return string updated uri
  */
 protected function replaceUri($uri)
 {
     if (strpos($uri, '://')) {
         return $uri;
     }
     if (in_array(rLastParse($uri, DOT), ['gif', 'jpg', 'png']) && file_exists(Paths::$file_root . SL . $uri)) {
         return $uri;
     }
     $position = strrpos($uri, '/vendor/');
     $file_name = $position !== false ? substr($uri, $position + 1) : substr($uri, strrpos($uri, SL) + 1);
     $file_path = null;
     if (substr($file_name, -4) == '.css') {
         $file_path = static::getCssPath($this->css) . SL . $file_name;
         if (!file_exists(Paths::$file_root . $file_path)) {
             $file_path = null;
         }
     }
     if (!isset($file_path)) {
         $file_path = substr(stream_resolve_include_path($file_name), strlen(Paths::$file_root));
         if (!$file_path || !file_exists(Paths::$file_root . $file_path)) {
             return $this->replaceLink(SL . $uri);
         }
     }
     return $this->getUriRoot() . $file_path;
 }
Пример #5
0
 /**
  * @param $mail   Mail_mime
  * @param $buffer string
  * @return string
  */
 protected function parseImages(Mail_mime $mail, $buffer)
 {
     $parent = '';
     $slash_count = substr_count(__DIR__, SL);
     while (!is_dir($parent . 'images')) {
         $parent .= '../';
         if (substr_count($parent, SL) > $slash_count) {
             $parent = '';
             break;
         }
     }
     $buffer = str_replace(['src=' . DQ . '/images/', 'src=' . Q . '/images/', '(url=/images/'], ['src=' . DQ . $parent . 'images/', 'src=' . Q . $parent . 'images/', '(url=' . $parent . 'images/)'], $buffer);
     foreach (['(' => ')', Q => Q, DQ => DQ] as $open => $close) {
         $pattern = '%\\' . $open . '([\\w\\.\\/\\-\\_]+\\.(?:gif|jpg|png))\\' . $close . '%';
         preg_match_all($pattern, $buffer, $matches);
         foreach ($matches[1] as $match) {
             $mail->addHTMLImage($match);
             foreach ($mail->_html_images as $key => $image) {
                 if ($image['name'] == $match) {
                     $mail->_html_images[$key]['c_type'] = 'image/' . rLastParse($match, '.');
                     $buffer = str_replace($match, 'cid:' . $image['cid'], $buffer);
                 }
             }
         }
     }
     return $buffer;
 }
Пример #6
0
 /**
  * @param $class_name string
  * @return Reflection_Source
  */
 public static function of($class_name)
 {
     $file = Names::classToPath($class_name) . '.php';
     if (Builder::isBuilt($class_name)) {
         $file = 'cache/compiled/' . str_replace(SL, '-', substr($file, 0, -4));
     }
     if (!file_exists($file)) {
         $file = strtolower(substr($file, 0, -4)) . SL . rLastParse($file, SL);
     }
     return new Reflection_Source($file);
 }
Пример #7
0
if ($argc < 3) {
    die('Arguments attendus : nickname helloworld' . LF);
}
$nickname = str_replace('.', '_', $argv[1]);
$project_name = str_replace('.', '_', $argv[2]);
$database = strtolower($nickname . '_' . $project_name);
$username = substr($database, 0, 16);
$project_password = uniqid();
$project_dir = __DIR__ . SL . strtolower($nickname . SL . $project_name);
$application_file = $project_dir . SL . 'Application.php';
$config_file = __DIR__ . SL . strtolower($project_name) . '.php';
$namespace = ucfirst($nickname) . BS . ucfirst($project_name);
$config_name = str_replace(BS, SL, $namespace);
$helloworld_template = $project_dir . SL . 'Application_home.html';
$alias_script = lLastParse(__DIR__, SL) . SL . strtolower($project_name) . '.php';
$application_dir = rLastParse(__DIR__, SL);
$local_file = __DIR__ . SL . 'loc.php';
$password_file = __DIR__ . SL . 'pwd.php';
$cache_dir = __DIR__ . SL . 'cache';
$tmp_dir = __DIR__ . SL . 'tmp';
$update_file = __DIR__ . SL . 'update';
$vendor_dir = __DIR__ . SL . 'vendor';
echo 'Initialization of your project ' . $namespace . '...' . LF;
echo '- Create directory ' . $project_dir . LF;
// /$nickname/$project/
if (!is_dir($project_dir)) {
    mkdir($project_dir, 0755, true);
}
echo '- Create application class file ' . $application_file . LF;
// /$nickname/$project/Application.php
file_put_contents($application_file, <<<EOT
Пример #8
0
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @param $class_name string
  * @return mixed
  * @todo factorize
  */
 public function run(Parameters $parameters, $form, $files, $class_name)
 {
     // convert form files to worksheets and session files
     if ($files) {
         /** @var $import Import */
         $import = $parameters->getMainObject(Import::class);
         $import->class_name = $class_name;
         $form = (new Post_Files())->appendToForm($form, $files);
         foreach ($form as $file) {
             if ($file instanceof File) {
                 if (!isset($session_files)) {
                     /** @var $session_files Files */
                     $session_files = Builder::create(Files::class);
                 }
                 $excel = Spreadsheet_File::fileToArray($file->temporary_file_name, $errors);
                 $worksheet_number = 0;
                 foreach ($excel as $temporary_file_name => $worksheet) {
                     if (filesize($temporary_file_name) > 1) {
                         $import_worksheet = Builder::create(Import_Worksheet::class, [$worksheet_number++, Import_Settings_Builder::buildArray($worksheet, $class_name), $csv_file = Builder::create(File::class, [$temporary_file_name])]);
                         $import_worksheet->errors = $errors;
                         $session_files->files[] = $csv_file;
                         $import->worksheets[] = $import_worksheet;
                     }
                 }
                 // only one file once
                 break;
             }
         }
         if (isset($session_files)) {
             Session::current()->set($session_files);
         }
     } else {
         /** @var $files File[] */
         $files = Session::current()->get(Files::class)->files;
         $parameters->unshift($import = Import_Builder_Form::build($form, $files));
         $import->class_name = $class_name;
     }
     // prepare parameters
     $parameters = $parameters->getObjects();
     $general_buttons = $this->getGeneralButtons($class_name);
     if (isset($parameters['constant_remove']) && strtoupper($parameters['constant_remove'][0]) === $parameters['constant_remove'][0]) {
         $parameters['constant_remove'] = rParse($parameters['constant_remove'], DOT);
     }
     foreach ($import->worksheets as $worksheet) {
         // apply controller parameters
         if (isset($parameters['constant_add']) && isset($worksheet->settings->classes[$parameters['constant_add']])) {
             $worksheet->settings->classes[$parameters['constant_add']]->addConstant();
         }
         if (isset($parameters['constant_remove']) && isset($worksheet->settings->classes[lLastParse($parameters['constant_remove'], DOT, 1, false)])) {
             $worksheet->settings->classes[lLastParse($parameters['constant_remove'], DOT, 1, false)]->removeConstant(rLastParse($parameters['constant_remove'], DOT, 1, true));
         }
         Custom_Settings_Controller::applyParametersToCustomSettings($worksheet->settings, array_merge($form, $parameters));
     }
     // recover empty Import_Settings (after loading empty one)
     /** @var $files File[] */
     $files = Session::current()->get(Files::class)->files;
     foreach ($import->worksheets as $worksheet_number => $worksheet) {
         if (empty($worksheet->settings->classes)) {
             $file = $files[$worksheet_number];
             $array = $file->getCsvContent();
             $import->worksheets[$worksheet_number] = new Import_Worksheet($worksheet_number, Import_Settings_Builder::buildArray($array, $class_name), $file);
         }
     }
     // get general buttons and customized import settings
     foreach ($import->worksheets as $worksheet_number => $worksheet) {
         $customized_import_settings = $worksheet->settings->getCustomSettings();
         $worksheet_general_buttons = $general_buttons;
         if (!isset($customized_import_settings[$worksheet->settings->name])) {
             unset($worksheet_general_buttons['delete']);
         }
         $parameters['custom'][$worksheet_number] = new StdClass();
         $parameters['custom'][$worksheet_number]->customized_lists = $customized_import_settings;
         $parameters['custom'][$worksheet_number]->general_buttons = $worksheet_general_buttons;
         $parameters['custom'][$worksheet_number]->settings = $worksheet->settings;
         $parameters['custom'][$worksheet_number]->aliases_property = Import_Array::getPropertiesAlias($worksheet->settings->getClassName());
         $parameters['custom'][$worksheet_number]->properties_alias = array_flip($parameters['custom'][$worksheet_number]->aliases_property);
     }
     // view
     $parameters[Template::TEMPLATE] = 'importPreview';
     return View::run($parameters, $form, $files, $class_name, Feature::F_IMPORT);
 }
Пример #9
0
 /**
  * @param $path   string
  * @param $prefix string
  * @return string
  */
 public function buildColumn($path, $prefix = '')
 {
     $join = $this->joins->add($path);
     $link_join = $this->joins->getIdLinkJoin($path);
     if (isset($link_join)) {
         $column = $link_join->foreign_alias . DOT . 'id';
     } elseif (isset($join)) {
         if ($join->type === Join::LINK) {
             $column = $join->foreign_alias . DOT . BQ . rLastParse($path, DOT, 1, true) . BQ;
         } else {
             $property = $this->joins->getStartingClass()->getProperty($path);
             $column = $property && $property->getAnnotation('link')->value == Link_Annotation::COLLECTION ? $join->master_column : $join->foreign_column;
             $column = $join->foreign_alias . DOT . BQ . $column . BQ;
         }
     } else {
         list($master_path, $foreign_column) = Builder::splitPropertyPath($path);
         if (!$master_path && $foreign_column == 'id') {
             $class = $this->joins->getStartingClassName();
             $i = 0;
             while ($class = (new Link_Class($class))->getLinkedClassName()) {
                 $i++;
             }
             $tx = 't' . $i;
         } else {
             $tx = 't0';
         }
         $column = !$master_path || $master_path === 'id' ? $tx . DOT . BQ . $prefix . $foreign_column . BQ : $this->joins->getAlias($master_path) . DOT . BQ . $prefix . $foreign_column . BQ;
     }
     return $column;
 }
Пример #10
0
 /**
  * Last element of a separated string
  *
  * @param $count integer
  * @return String
  */
 public function last($count = 1)
 {
     foreach ([':', DOT, '-', ','] as $char) {
         if (strrpos($this->value, $char) !== false) {
             return new String(rLastParse($this->value, $char, $count, true));
         }
     }
     return new String($this->value);
 }
Пример #11
0
 /**
  * @return boolean
  */
 public function isConstructor()
 {
     return $this->name === '__construct' || $this->name === rLastParse($this->class->name, BS, 1, true);
 }
Пример #12
0
 /**
  * Extract the object identifier from a short standard DELETE query string
  *
  * @param $query string
  * @return integer
  */
 private function extractId($query)
 {
     $id = rLastParse($query, LF . 'WHERE id = ');
     return is_numeric($id) ? intval($id) : null;
 }
Пример #13
0
 /**
  * Returns an expanded list of properties. Source element must be a list of Reflection_Property
  *
  * @param $template Template
  * @return Reflection_Property
  */
 public function getExpand(Template $template)
 {
     $property = reset($template->objects);
     $expanded = Integrated_Properties::expandUsingProperty($expanded, $property, $template->getParentObject($property->class));
     $result = $expanded ? $expanded : [$property];
     if ($expand_property_path = $template->getParameter(Parameter::EXPAND_PROPERTY_PATH)) {
         foreach ($result as $property) {
             $property->path = $expand_property_path . DOT . $property->path;
             if ($property instanceof Reflection_Property_Value && !$property->display) {
                 $property->display = rLastParse($property->path, DOT . DOT, 1, true);
             }
         }
     }
     return $result;
 }
Пример #14
0
 /**
  * @param $file_name string
  * @return Type or null if the file type is unknown
  */
 public static function build($file_name)
 {
     $file_extension = rLastParse($file_name, DOT);
     $type = Type::fileExtensionToTypeString($file_extension);
     return isset($type) ? new Type($type) : new Type('empty/empty');
 }