Ejemplo n.º 1
0
 /**
  * Returns a new instance of an object, but sets all its properties values to empty
  *
  * The empty value depends on the type of the property, simple type get an empty value of the
  * same type. Object, resource, callable properties get an empty value of null.
  *
  * @param $class_name string
  * @return object
  */
 public static function create($class_name)
 {
     $object = Builder::create($class_name);
     foreach ((new Reflection_Class($class_name))->accessProperties() as $property) {
         if (!$property->isStatic()) {
             switch ($property->getType()->asString()) {
                 case Type::INTEGER:
                 case Type::FLOAT:
                     $value = 0;
                     break;
                 case Type::STRING:
                     $value = '';
                     break;
                 case Type::BOOLEAN:
                     $value = false;
                     break;
                 case Type::_ARRAY:
                     $value = [];
                     break;
                 default:
                     $value = null;
             }
             $property->setValue($object, $value);
         }
     }
     return $object;
 }
Ejemplo n.º 2
0
 /**
  * @return Body
  */
 protected function buildBody()
 {
     $body = parent::buildBody();
     $row = $this->buildRow(Builder::create($this->class_name));
     $row->addClass('new');
     $body->addRow($row);
     return $body;
 }
Ejemplo n.º 3
0
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $class_name string
  * @return mixed[]
  */
 protected function getViewParameters(Parameters $parameters, $form, $class_name)
 {
     $parameters = $parameters->getObjects();
     $object = reset($parameters);
     if (empty($object) || !is_object($object) || !is_a($object, $class_name, true)) {
         $object = Builder::create($class_name);
         $parameters = array_merge([$class_name => $object], $parameters);
     }
     return $parameters;
 }
Ejemplo n.º 4
0
 /**
  * Returns a new instance of an object, but sets all its properties values to null
  *
  * @param $class_name string
  * @return object
  */
 public static function create($class_name)
 {
     $object = Builder::create($class_name);
     foreach ((new Reflection_Class($class_name))->accessProperties() as $property) {
         if (!$property->isStatic()) {
             $property->setValue($object, null);
         }
     }
     return $object;
 }
Ejemplo n.º 5
0
 /**
  * Run the default json controller
  *
  * @param $parameters Parameters
  * @param $form array
  * @param $files array
  * @param $class_name string
  * @return string
  */
 public function run(Parameters $parameters, $form, $files, $class_name)
 {
     $parameters = $parameters->getObjects();
     // read all objects corresponding to class name
     if (!$parameters) {
         return json_encode(Dao::readAll(Names::setToClass($class_name, false), [Dao::sort()]));
     }
     // read object
     $first_parameter = reset($parameters);
     if (is_object($first_parameter)) {
         return json_encode($first_parameter);
     }
     // search objects for autocomplete combo pull-down list
     if (isset($parameters['term'])) {
         $element_class_name = Names::setToClass($class_name, false);
         $search = null;
         if (!empty($parameters['term'])) {
             $search = (new Search_Array_Builder())->buildMultiple(new Reflection_Class($element_class_name), $parameters['term'], '', '%');
         }
         if (isset($parameters['filters']) && $parameters['filters']) {
             if (!(is_object($search) && $search->isAnd())) {
                 $search = Dao\Func::andOp($search ? [$search] : []);
             }
             foreach ($parameters['filters'] as $filter_name => $filter_value) {
                 $search->arguments[$filter_name] = $filter_value[0] == '!' ? Dao\Func::notEqual(substr($filter_value, 1)) : $filter_value;
             }
             if (count($search->arguments) == 1) {
                 reset($search->arguments);
                 $search = [key($search->arguments) => current($search->arguments)];
             }
         }
         $objects = [];
         // first object only
         if (isset($parameters['first']) && $parameters['first']) {
             $objects = Dao::search($search, $element_class_name, [Dao::sort(), Dao::limit(1)]);
             $source_object = $objects ? reset($objects) : Builder::create($element_class_name);
             return json_encode(new Autocomplete_Entry(Dao::getObjectIdentifier($source_object), strval($source_object)));
         } else {
             $search_options = [Dao::sort()];
             if (isset($parameters['limit'])) {
                 $search_options[] = Dao::limit($parameters['limit']);
             }
             foreach (Dao::search($search, $element_class_name, $search_options) as $source_object) {
                 $objects[] = new Autocomplete_Entry(Dao::getObjectIdentifier($source_object), strval($source_object));
             }
             return json_encode($objects);
         }
     } elseif (isset($parameters['id'])) {
         $element_class_name = Names::setToClass($class_name);
         $source_object = Dao::read($parameters['id'], $element_class_name);
         return json_encode(new Autocomplete_Entry(Dao::getObjectIdentifier($source_object), strval($source_object)));
     }
     return '';
 }
Ejemplo n.º 6
0
 /**
  * @before SAF\Framework\Dao\Data_Link::write($this)
  */
 public function setNumber()
 {
     if (isA($this, Has_Counter::class)) {
         /** @var $counter Counter */
         $counter = Dao::searchOne(['class_name' => get_class($this)], Counter::class);
         if (!isset($counter)) {
             $counter = Builder::create(Counter::class, [get_class($this)]);
         }
         $this->setCounter($counter->increment());
     }
 }
Ejemplo n.º 7
0
 /**
  * @param $serialized string
  * @return void
  */
 public function unserialize($serialized)
 {
     $this->files = [];
     foreach (unserialize($serialized) as $file_name => $temporary_file_name) {
         /** @var $file File */
         $file = Builder::create(File::class);
         $file->name = $file_name;
         $file->temporary_file_name = $temporary_file_name;
         $this->files[] = $file;
     }
 }
Ejemplo n.º 8
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);
     }
 }
Ejemplo n.º 9
0
 /**
  * @param $source Reflection_Source
  */
 public function onCompileSource(Reflection_Source $source)
 {
     Dao::begin();
     foreach ($source->getClasses() as $class) {
         /** @var $log Compiler_Log */
         $log = Builder::create(Compiler_Log::class);
         $log->class_name = $class->getName();
         $log->date_time = Date_Time::now();
         Dao::write($log);
         $this->log_flag = true;
     }
     Dao::commit();
 }
Ejemplo n.º 10
0
 /**
  * Get the object of class $class_name from session
  *
  * @param $class_name     string
  * @param $create_default boolean Create a default object for the class name if does not exist
  * @return object|null
  */
 public function get($class_name, $create_default = false)
 {
     if (isset($this->current[$class_name])) {
         $current = $this->current[$class_name];
         if (is_array($current)) {
             $current = $current[1];
             $this->current[$class_name] = $current = is_numeric($current) ? Dao::read($current, $class_name) : unserialize($current);
         }
         return $current;
     } elseif ($create_default) {
         return $this->current[$class_name] = Builder::create($class_name);
     } else {
         return null;
     }
 }
Ejemplo n.º 11
0
 /**
  * Returns a new instance of a search-formatted object of given class
  *
  * This creates an object with unset properties, as only set properties are used for searches.
  * Private or protected properties can't be unset : they are kept with a null value.
  *
  * @param $class_name string
  * @return object
  */
 public static function create($class_name)
 {
     $object = Builder::create($class_name);
     foreach ((new Reflection_Class(get_class($object)))->accessProperties() as $property) {
         if (!$property->isStatic()) {
             if ($property->isPublic()) {
                 $name = $property->name;
                 if (!isset($object->{$name}) || $object->{$name} !== $object) {
                     unset($object->{$name});
                 }
             } else {
                 $property->setValue($object, null);
             }
         }
     }
     return $object;
 }
Ejemplo n.º 12
0
 /**
  * @param $form             array
  * @param $name_element     array
  * @param $tmp_name_element array
  * @return array
  */
 private function appendToFormRecurse($form, $name_element, $tmp_name_element)
 {
     foreach ($name_element as $key => $name_sub_element) {
         if (is_array($name_sub_element)) {
             if (!isset($form[$key])) {
                 $form[$key] = [];
             }
             $form[$key] = $this->appendToFormRecurse($form[$key], $name_sub_element, $tmp_name_element[$key]);
         } else {
             /** @var $file File */
             $file = Builder::create(File::class);
             $file->name = $name_sub_element;
             $file->temporary_file_name = $tmp_name_element[$key];
             $form[$key] = $file;
         }
     }
     return $form;
 }
Ejemplo n.º 13
0
 /**
  * Encodes the email into MIME format
  *
  * Returns the MIME Multipart string
  * If the mail is plain text without attachment, the plain text is returned without any change
  *
  * @return string
  */
 public function encode()
 {
     if ($this->email->attachments || strpos($this->email->content, '<body')) {
         /** @var $mail Mail_mime */
         $mail = Builder::create(Mail_mime::class);
         $body = $this->parseImages($mail, $this->email->content);
         $error_reporting = error_reporting();
         error_reporting(E_ALL & ~E_WARNING);
         $mail->setTXTBody(convert_html_to_text($this->email->content));
         error_reporting($error_reporting);
         $mail->setHTMLBody($body);
         $this->addAttachments($mail);
         $mime_params = ['text_encoding' => '8bit', 'text_charset' => 'UTF-8', 'html_charset' => 'UTF-8', 'head_charset' => 'UTF-8'];
         $body = $mail->get($mime_params);
         $this->email->headers = $mail->headers($this->email->getHeadersAsStrings());
         return $body;
     }
     return $this->email->content;
 }
Ejemplo n.º 14
0
 /**
  * @param $template_file string
  * @param $parameters    array
  * @param $feature_name string
  * @return string
  */
 protected function executeTemplate($template_file, $parameters, $feature_name)
 {
     if (isset($parameters[Template::TEMPLATE])) {
         unset($parameters[Template::TEMPLATE]);
     }
     if (isset($parameters[Template::TEMPLATE_CLASS])) {
         $template_class = $parameters[Template::TEMPLATE_CLASS];
     } elseif (isset($parameters[Template::TEMPLATE_NAMESPACE])) {
         $template_class = $parameters[Template::TEMPLATE_NAMESPACE] . BS . 'Html_Template';
         unset($parameters[Template::TEMPLATE_NAMESPACE]);
     } else {
         $template_class = Template::class;
     }
     /** @var $template Template */
     $template = Builder::create($template_class, [reset($parameters), $template_file, $feature_name]);
     $template->setParameters($parameters);
     $current = Framework\View::current();
     if ($current instanceof Engine && ($css = $current->getCss())) {
         $template->setCss($css);
     }
     return $template->parse();
 }
Ejemplo n.º 15
0
 /**
  * @param $properties_list Reflection_Property[] new indices will be 'property.sub_property'
  * @param $property        Reflection_Property
  * @param $object          object
  * @param $property_name   string
  * @param $display_prefix  string
  * @param $blocks          string[]
  * @return Reflection_Property[] added properties list (empty if none applies) indices are
  *         'property.sub_property'
  * @todo probably things to clean up (was patched for 'all properties as values' without controls)
  */
 private static function expandUsingPropertyInternal(&$properties_list, $property, $object, $property_name, $display_prefix = '', $blocks = [])
 {
     $expanded = [];
     /** @var $integrated Integrated_Annotation */
     $integrated = $property->getListAnnotation('integrated');
     if ($integrated->value && !$property->isStatic()) {
         if ($integrated->has('block')) {
             $blocks[$property->path ?: $property->name] = $property->path ?: $property->name;
         }
         $integrated_simple = $integrated->has('simple');
         $sub_properties_class = $property->getType()->asReflectionClass();
         $expand_properties = $sub_properties_class->getProperties([T_EXTENDS, T_USE]);
         $value = $property->getValue($object) ?: Builder::create($property->getType()->asString());
         foreach ($expand_properties as $sub_property_name => $sub_property) {
             if (!$sub_property->getListAnnotation('user')->has(User_Annotation::INVISIBLE)) {
                 $display = $display_prefix . ($display_prefix ? DOT : '') . $property->name . DOT . $sub_property_name;
                 $sub_prefix = $integrated_simple ? $display_prefix : $display;
                 if ($more_expanded = self::expandUsingPropertyInternal($properties_list, $sub_property, $value, $property_name . DOT . $sub_property_name, $sub_prefix, $blocks)) {
                     $expanded = array_merge($expanded, $more_expanded);
                 } else {
                     $sub_property = new Reflection_Property_Value($sub_property->class, $sub_property->name, $value, false, true);
                     $sub_property->final_class = $sub_properties_class->name;
                     $sub_property->display = $integrated_simple ? $integrated->has('alias') ? $sub_property->getAnnotation('alias')->value : $sub_property_name : $display;
                     /** @var $block_annotation List_Annotation */
                     $block_annotation = $sub_property->setAnnotationLocal('block');
                     foreach ($blocks as $block) {
                         $block_annotation->add($block);
                     }
                     $sub_property->path = $property_name . DOT . $sub_property_name;
                     $properties_list[$property_name . DOT . $sub_property_name] = $sub_property;
                     $expanded[$property_name . DOT . $sub_property_name] = $sub_property;
                 }
             }
         }
     }
     return $expanded;
 }
Ejemplo n.º 16
0
 /**
  * @param $controller  string
  * @param $method_name string
  * @param $uri         Uri
  * @param $post        array
  * @param $files       array
  * @return string
  */
 private function executeController($controller, $method_name, $uri, $post, $files)
 {
     $controller = Builder::create($controller);
     if ($controller instanceof Class_Controller) {
         return call_user_func_array([$controller, $method_name], [$uri->parameters, $post, $files, $uri->feature_name, $uri->controller_name]);
     } else {
         return call_user_func_array([$controller, $method_name], [$uri->parameters, $post, $files, $uri->controller_name, $uri->feature_name]);
     }
 }
Ejemplo n.º 17
0
 /**
  * Loads a Data_List_Settings from the Settings set
  *
  * If no Data_List_Settings named $name is stored, a new one will be returned
  *
  * @param $class_name string
  * @param $name       string
  * @return Custom_Settings
  */
 public static function load($class_name, $name)
 {
     /** @var $setting Setting */
     $setting = new Setting($class_name . DOT . static::customId() . DOT . $name);
     $setting = Dao::searchOne($setting);
     $custom_settings = isset($setting) ? $setting->value : Builder::create(get_called_class(), [$class_name]);
     $custom_settings->setting = self::currentUserSetting($class_name);
     $custom_settings->setting->value = $custom_settings;
     return $custom_settings;
 }
Ejemplo n.º 18
0
 /**
  * @param $row                     array
  * @param $class                   Import_Class
  * @param $class_properties_column integer[]|string[]
  * @return object
  */
 private function writeNewObject($row, Import_Class $class, $class_properties_column)
 {
     $object = Builder::create($class->class_name);
     foreach (array_keys($class->identify_properties) as $property_name) {
         $object->{$property_name} = $row[$class_properties_column[$property_name]];
     }
     foreach (array_keys($class->write_properties) as $property_name) {
         $object->{$property_name} = $row[$class_properties_column[$property_name]];
     }
     if ($this->simulation) {
         $this->simulateNew($class, $object);
     }
     Dao::write($object);
     return $object;
 }
Ejemplo n.º 19
0
 /**
  * Gets the main object from the parameters
  *
  * If no main object is set (eq first parameter is not an object), create it using class name.
  * Beware : the created object will then automatically be added to the beginning
  * of the parameters list.
  *
  * @param $class_name           string|object
  * @param $search_by_properties string[]
  * @return object
  */
 public function getMainObject($class_name = null, $search_by_properties = [])
 {
     if (is_object($class_name)) {
         $default_object = $class_name;
         $class_name = get_class($class_name);
     }
     reset($this->parameters);
     $object = $this->getObject(key($this->parameters));
     if (!$object || !is_object($object)) {
         if ($search_by_properties) {
             $object = $this->searchMainObject($class_name, $search_by_properties);
         }
         if ((!$object || !is_object($object)) && !$class_name) {
             $class_name = $this->uri->controller_name;
         }
     }
     if (!$object || !is_object($object) || isset($class_name) && !is_a($object, $class_name)) {
         $object = isset($default_object) ? $default_object : (isset($class_name) && @class_exists($class_name) ? Builder::create($class_name) : Set::instantiate($class_name));
         $this->parameters = array_merge([get_class($object) => $object], $this->parameters);
     }
     return $object;
 }
Ejemplo n.º 20
0
 /**
  * @param $text string
  * @return string
  */
 public static function parse($text)
 {
     /** @var $textile Textile */
     $textile = Builder::create(Textile::class);
     return $textile->textileThis($text);
 }
Ejemplo n.º 21
0
 /**
  * Gets a plugin object
  * If no plugin of this class name exists, the class is instantiated and the plugin registered
  *
  * @param $class_name string
  * @param $level      string
  * @param $register   boolean
  * @param $activate   boolean
  * @return Plugin
  */
 public function get($class_name, $level = null, $register = false, $activate = false)
 {
     /** @var $plugin Plugin|boolean|string */
     if (isset($this->plugins[$class_name])) {
         $plugin = $this->plugins[$class_name];
     } elseif (!($constructor = (new Reflection_Class($class_name))->getConstructor()) || !$constructor->getNumberOfParameters()) {
         $plugin = Builder::create($class_name);
     } else {
         return null;
     }
     // unserialize plugin
     if (!is_object($plugin)) {
         static $protect = null;
         if ($class_name == $protect) {
             return null;
         }
         $protect = $class_name;
         if (!isset($plugin)) {
             trigger_error('Get plugin ' . $class_name . ' : it does not exist', E_USER_ERROR);
         }
         $serialized = $plugin;
         // configuration
         if (is_array($serialized)) {
             $plugin = Builder::create($class_name, [$serialized]);
             /** @noinspection PhpUndefinedFieldInspection */
             $plugin->plugin_configuration = $serialized;
         } elseif (is_string($serialized)) {
             if (is_a($class_name, Serializable::class, true)) {
                 $plugin = unserialize($serialized);
             } else {
                 $configuration = unserialize($serialized);
                 $plugin = Builder::create($class_name, [$configuration]);
                 /** @noinspection PhpUndefinedFieldInspection */
                 $plugin->plugin_configuration = $configuration;
             }
         } else {
             $plugin = Builder::create($class_name);
         }
         // store plugin object into manager
         $this->plugins[$class_name] = $plugin;
         if (isset($level)) {
             $this->plugins_tree[$level][$class_name] = $plugin;
         } else {
             foreach ($this->plugins_tree as $level => $plugins) {
                 if (isset($plugins[$class_name])) {
                     $this->plugins_tree[$level][$class_name] = $plugin;
                     break;
                 }
             }
         }
         $protect = null;
         $activate = true;
     }
     // register plugin
     if ($register && $plugin instanceof Registerable) {
         $weaver = isset($this->plugins[Weaver::class]) ? $this->plugins[Weaver::class] : null;
         /** @var $plugin Registerable */
         $plugin->register(new Register(isset($plugin->plugin_configuration) ? $plugin->plugin_configuration : null, $weaver));
         $activate = true;
     }
     // activate plugin
     if ($activate && $plugin instanceof Activable) {
         if (isset($this->activated[$class_name])) {
             trigger_error('Plugin ' . $class_name . ' just registered and already activated', E_USER_WARNING);
         } else {
             /** @var $plugin Activable */
             $plugin->activate();
             $this->activated[$class_name] = $plugin;
         }
     }
     return $plugin;
 }
Ejemplo n.º 22
0
 /**
  * @param $result mixed[]
  * @param $first  boolean
  * @return array
  */
 private function resultToRow($result, $first)
 {
     $row = [];
     for ($i = 0; $i < $this->column_count; $i++) {
         $j = $this->i_to_j[$i];
         if (!isset($this->classes[$j])) {
             $row[$this->columns[$j]] = $result[$i];
         } else {
             if (!isset($row[$this->columns[$j]])) {
                 // TODO LOW try to get the object from object map to avoid multiple instances
                 $row[$this->columns[$j]] = Builder::create($this->classes[$j]);
                 if ($first && !isset($this->reflection_classes[$this->classes[$j]])) {
                     $class = new Reflection_Class($this->classes[$j]);
                     $class->accessProperties();
                     $this->reflection_classes[$this->classes[$j]] = $class;
                 }
             }
             $property_name = $this->column_names[$i];
             if ($property_name === 'id') {
                 $this->link->setObjectIdentifier($row[$this->columns[$j]], $result[$i]);
             } else {
                 $row[$this->columns[$j]]->{$property_name} = $result[$i];
             }
         }
     }
     return $row;
 }
Ejemplo n.º 23
0
 /**
  * @param $property_name string
  * @param $format_value  boolean
  * @return mixed
  */
 protected function parseSingleValue($property_name, $format_value = true)
 {
     $source_object = $object = reset($this->objects);
     if (!strlen($property_name)) {
         $object = $this->parseParent();
     } elseif (is_numeric($property_name) && is_string($object)) {
         $object = substr($object, $property_name, 1);
     } elseif ($property_name === '#') {
         $object = reset($this->var_names);
     } elseif (strpos($property_name, '?')) {
         $object = $this->parseConditional($property_name);
     } elseif ($property_name[0] == Q && substr($property_name, -1) == Q || $property_name[0] == DQ && substr($property_name, -1) == DQ) {
         $object = $this->parseConstant($property_name);
     } elseif (isset($this->parse_class_name)) {
         if ($property_name === 'class') {
             $object = $this->parse_class_name;
         } elseif (method_exists($this->parse_class_name, $property_name)) {
             $object = $this->parseStaticMethod($this->parse_class_name, $property_name);
         } elseif (property_exists($this->parse_class_name, $property_name)) {
             $object = $this->parseStaticProperty($this->parse_class_name, $property_name);
         } elseif (defined($this->parse_class_name . '::' . $property_name)) {
             $object = constant($this->parse_class_name . '::' . $property_name);
         } else {
             $object = isA($this->parse_class_name, $this->parseClassName($property_name));
         }
         $this->parse_class_name = null;
     } elseif ($property_name[0] >= 'A' && $property_name[0] <= 'Z') {
         if (is_array($object) && (isset($object[$property_name]) || !@class_exists($property_name))) {
             $object = $this->parseArrayElement($object, $property_name);
         } elseif (strlen($property_name) > 1 && ($property_name[1] >= 'a' && $property_name[1] <= 'z' || strpos($property_name, BS) !== false)) {
             $this->parse_class_name = $this->parseClassName($property_name);
         } else {
             $object = $this->parseConst($object, $property_name);
         }
     } elseif ($property_name[0] === AT) {
         $object = $this->parseFunc(substr($property_name, 1));
     } elseif ($i = strpos($property_name, '(')) {
         if ((is_object($object) || ctype_upper($object[0])) && method_exists($object, substr($property_name, 0, $i))) {
             $object = $this->parseMethod($object, $property_name);
         } else {
             $object = $this->callFunc(reset($this->objects), $property_name);
         }
     } elseif (is_array($object)) {
         $object = $this->parseArrayElement($object, $property_name);
     } elseif (!is_object($object) && !isset($this->parameters[$property_name])) {
         $object = $this->parseString($object, $property_name);
     } elseif ((is_object($object) || is_string($object) && !empty($object) && ctype_upper($object[0])) && method_exists($object, $property_name)) {
         if ($property_name == 'value' && $object instanceof Reflection_Property && ($builder = $object->getAnnotation('widget')->value) && is_a($builder, Property::class, true)) {
             $builder = Builder::create($builder, [$object, $this->parseMethod($object, $property_name), $this]);
             /** @var $builder Property */
             $object = $builder->buildHtml();
             $format_value = false;
         } else {
             $object = $this->parseMethod($object, $property_name);
         }
     } elseif (isset($object->{$property_name})) {
         $object = $this->parseProperty($object, $property_name);
     } elseif (isset($this->parameters[$property_name])) {
         $object = $this->parseParameter($object, $property_name);
     } else {
         $object = $this->parseProperty($object, $property_name);
     }
     if ($format_value && $source_object instanceof Reflection_Property && $property_name == 'value') {
         $object = (new Reflection_Property_View($source_object))->formatValue($object);
     }
     return $object;
 }
Ejemplo n.º 24
0
 /**
  * @param $serialized string
  */
 public function unserialize($serialized)
 {
     $this->compilers = [];
     foreach (unserialize($serialized) as $wave_number => $compilers) {
         foreach ($compilers as $class_name) {
             $this->compilers[$wave_number][] = Session::current()->plugins->has($class_name) ? Session::current()->plugins->get($class_name) : Builder::create($class_name);
         }
     }
 }
Ejemplo n.º 25
0
 /**
  * @param $object        object
  * @param $property      Reflection_Property
  * @param $value         string
  * @param $null_if_empty boolean
  * @return boolean true if property value is null
  */
 private function buildProperty($object, Reflection_Property $property, $value, $null_if_empty)
 {
     $is_null = $null_if_empty;
     // use widget
     if ($this->from_form && ($builder = $property->getAnnotation('widget')->value) && is_a($builder, Property::class, true)) {
         $builder = Builder::create($builder, [$property, $value]);
         /** @var $builder Property */
         $value2 = $builder->buildValue($object, $null_if_empty);
         if ($value2 !== Property::DONT_BUILD_VALUE) {
             $value = $value2;
             $done = true;
         }
     }
     if (!isset($done)) {
         $type = $property->getType();
         if ($type->isBasic()) {
             // password
             if ($encryption = $property->getAnnotation('password')->value) {
                 if ($value == Password::UNCHANGED) {
                     return true;
                 }
                 $value = (new Password($value, $encryption))->encrypted();
             } else {
                 $value = $this->buildBasicValue($property, $value);
             }
         } elseif (is_array($value)) {
             $link = $property->getAnnotation('link')->value;
             // object
             if ($link == Link_Annotation::OBJECT) {
                 $class_name = $property->getType()->asString();
                 $value = $this->buildObjectValue($class_name, $value, $null_if_empty);
             } elseif ($link == Link_Annotation::COLLECTION) {
                 $class_name = $property->getType()->getElementTypeAsString();
                 $value = $this->buildCollection($class_name, $value, $null_if_empty, $object);
             } else {
                 $value = $this->buildMap($value, $property->getType()->getElementTypeAsString(), $link);
             }
         } elseif (isset($value) && $property->getAnnotation('output')->value == 'string') {
             /** @var $object_value Stringable */
             $object_value = Builder::create($property->getType()->asString());
             $object_value->fromString($value);
             $value = $object_value;
         }
     }
     // the property value is set only for official properties, if not default and not empty
     $property_name = $property->name;
     if ($value !== '' || !$property->getType()->isClass()) {
         $object->{$property_name} = $value;
     }
     if (!$property->isValueEmptyOrDefault($value)) {
         $is_null = false;
     }
     return $is_null;
 }
 /**
  * @param $object object
  * @return string HTML combo-box with filters
  */
 protected function getCombo($object)
 {
     $class_name = get_class($object);
     $edit = new Html_Builder_Type('replace_with', new Type($class_name), Builder::create($class_name));
     return $edit->buildObject(null, $this->getFilters($object));
 }
Ejemplo n.º 27
0
 /**
  * Parse a variable / function / include and returns its return value
  *
  * @param $property_name string can be an unique var or path.of.vars
  * @param $format_value  boolean
  * @return string var value after reading value / executing specs (can be an object)
  */
 protected function parseSingleValue($property_name, $format_value = true)
 {
     $property = $source_object = reset($this->objects);
     if ($property instanceof Reflection_Property_Value && $property_name == 'value') {
         if (($builder = $property->getAnnotation('widget')->value) && is_a($builder, Property::class, true)) {
             $builder = Builder::create($builder, [$property, $property->value(), $this]);
             /** @var $builder Property */
             $builder->parameters[Feature::F_EDIT] = Feature::F_EDIT;
             $value = $builder->buildHtml();
             if ($builder instanceof Value_Widget) {
                 $value = (new Html_Builder_Property($property, $value))->setTemplate($this)->build();
             }
         } else {
             $value = $property->getType()->isBoolean() ? $property->value() : parent::parseSingleValue($property_name, false);
             if (($preprop = lLastParse($property->pathAsField(), '[', 1, false)) && (!isset($this->cache[self::PARSED_ID]) || !isset($this->cache[self::PARSED_ID][$this->getFormId()]) || !isset($this->cache[self::PARSED_ID][$this->getFormId()][$preprop]))) {
                 $this->cache[self::PARSED_ID][$this->getFormId()][$preprop] = true;
                 if ($property instanceof Reflection_Property_Value) {
                     $parent_object = $property->getObject();
                     $id = isset($parent_object) ? Dao::getObjectIdentifier($parent_object) : null;
                     $html_builder_type = new Html_Builder_Type('id', null, $id, $preprop);
                     $id_value = $html_builder_type->setTemplate($this)->build();
                 } else {
                     $id_value = '';
                 }
             } else {
                 $id_value = '';
             }
             if ($property->getAnnotation('output')->value == 'string') {
                 $property->setAnnotationLocal('var')->value = 'string';
                 $value = isset($value) ? strval($value) : null;
                 $id_value = '';
             }
             $value = $id_value . (new Html_Builder_Property($property, $value))->setTemplate($this)->build();
         }
     } else {
         $value = parent::parseSingleValue($property_name);
     }
     return $value;
 }
Ejemplo n.º 28
0
 /**
  * @param $list_settings Data_List_Settings
  * @return array search-compatible search array
  */
 protected function applySearchParameters(Data_List_Settings $list_settings)
 {
     /** @var $search_parameters_parser Search_Parameters_Parser */
     $search_parameters_parser = Builder::create(Search_Parameters_Parser::class, [$list_settings->class_name, $list_settings->search]);
     $result = $search_parameters_parser->parse();
     foreach ((new Reflection_Class($list_settings->class_name))->getAnnotations('on_data_list') as $execute) {
         /** @var $execute Method_Annotation */
         if ($execute->call($list_settings->class_name, [&$result]) === false) {
             break;
         }
     }
     return $result;
 }
Ejemplo n.º 29
0
 /**
  * @param $view             string
  * @param $view_method_name string
  * @param $parameters       array
  * @param $form             array
  * @param $files            array
  * @param $class_name       string
  * @param $feature_name     string
  * @return mixed
  */
 private static function executeView($view, $view_method_name, $parameters, $form, $files, $class_name, $feature_name)
 {
     $object = reset($parameters);
     $view_object = is_object($object) && isA($object, $view) ? reset($parameters) : Builder::create($view);
     return $view_object->{$view_method_name}($parameters, $form, $files, $class_name, $feature_name);
 }
Ejemplo n.º 30
0
 /**
  * Send an email using its account connection information
  * or the default SMTP account configuration.
  *
  * @param $email  Email
  * @return boolean|string true if sent, error message if string
  */
 public function send(Email $email)
 {
     // email send configuration
     $params = $this->sendConfiguration($email);
     // mime encode of email (for html, images and attachments)
     /** @var $encoder Encoder */
     $encoder = Builder::create(Encoder::class, [$email]);
     $content = $encoder->encode();
     // send email using PEAR Mail and Net_SMTP features
     /** @var $mail Mail_smtp */
     $mail = (new Mail())->factory('smtp', $params);
     $error_reporting = error_reporting();
     error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
     $send_result = $mail->send($email->getRecipientsAsStrings(), $email->getHeadersAsStrings(), $content);
     error_reporting($error_reporting);
     // user error when errors
     if ($send_result instanceof PEAR_Error) {
         return $email->send_message = strval($send_result);
     }
     $email->send_date = new Date_Time();
     /** @noinspection PhpUndefinedFieldInspection */
     $email->uidl = $mail->queued_as;
     return true;
 }