コード例 #1
0
 public function testBuildMultiple()
 {
     $this->assume(__METHOD__ . '.simple', (new Tools\Search_Array_Builder())->buildMultiple(['pro1', 'pro2'], 'test'), Func::orOp(['pro1' => 'test', 'pro2' => 'test']));
     $this->assume(__METHOD__ . '.and', (new Tools\Search_Array_Builder())->buildMultiple(['pro1', 'pro2'], 'test what'), Func::andOp([Func::orOp(['pro1' => 'test', 'pro2' => 'test']), Func::orOp(['pro1' => '%what', 'pro2' => '%what'])]));
     $this->assume(__METHOD__ . '.or', (new Tools\Search_Array_Builder())->buildMultiple(['pro1', 'pro2'], 'test,what'), Func::orOp(['pro1' => ['test', 'what'], 'pro2' => ['test', 'what']]));
     $this->assume(__METHOD__ . '.mix', (new Tools\Search_Array_Builder())->buildMultiple(['pro1', 'pro2'], 'test,what else'), Func::orOp(['pro1' => ['test', Func::andOp(['what', '%else'])], 'pro2' => ['test', Func::andOp(['what', '%else'])]]));
 }
コード例 #2
0
ファイル: Compiler.php プロジェクト: TuxBoy/Demo-saf
 /**
  * Extends the list of sources to compile
  *
  * When you modify a file, all these classes may have their matching mysql structure changed :
  * - the class itself
  * - all classes that extend the class or use the trait
  *
  * @param &$sources Reflection_Source[]
  * @return Reflection_Source[] added sources list
  */
 public function moreSourcesToCompile(&$sources)
 {
     $added = [];
     // Builder is disabled during the listing as we want to get the original linked class name when
     // reading class annotation @link
     Builder::current()->enabled = false;
     /** @var $search Dependency */
     $search = Search_Object::create(Dependency::class);
     $search->file_name = Func::notLike('cache/%');
     $search->type = Func::orOp([Dependency::T_EXTENDS, Dependency::T_USE]);
     foreach ($sources as $source) {
         foreach ($source->getClasses() as $class) {
             while ($linked_class = $class->getAnnotation('link')->value) {
                 $source = Reflection_Class::of($linked_class)->source;
                 if (!isset($sources[$source->file_name])) {
                     $sources[$source->file_name] = $source;
                     $added[$source->file_name] = $source;
                 }
                 $class = $source->getClass($linked_class);
             }
             $search->dependency_name = $class->name;
             foreach (Dao::search($search, Dependency::class) as $dependency) {
                 /** @var $dependency Dependency */
                 if (!isset($sources[$dependency->file_name])) {
                     $source = new Reflection_Source($dependency->file_name);
                     $sources[$dependency->file_name] = $source;
                     $added[$dependency->file_name] = $source;
                 }
             }
         }
     }
     Builder::current()->enabled = true;
     return $added;
 }
コード例 #3
0
 /**
  * @param $property_names_or_class string[]|Reflection_Class
  * @param $search_phrase string
  * @param $prepend string
  * @param $append string
  * @return Logical|array
  */
 public function buildMultiple($property_names_or_class, $search_phrase, $prepend = '', $append = '')
 {
     $property_names = $property_names_or_class instanceof Reflection_Class ? $this->classRepresentativeProperties($property_names_or_class) : $property_names_or_class;
     // search phrase contains OR
     if (strpos($search_phrase, $this->or) !== false) {
         $or = [];
         foreach ($property_names as $property_name) {
             $or[$property_name] = $this->build('', $search_phrase, $prepend, $append);
         }
         $result = Func::orOp($or);
     } elseif (strpos($search_phrase, $this->and) !== false) {
         $and = [];
         foreach (explode($this->and, $search_phrase) as $search) {
             $and[] = $this->buildMultiple($property_names, $search, $prepend, $append);
             $prepend = '%';
         }
         $result = Func::andOp($and);
     } else {
         $or = [];
         foreach ($property_names as $property_name) {
             $or[$property_name] = $prepend . $search_phrase . $append;
         }
         $result = count($or) > 1 ? Func::orOp($or) : $or;
     }
     return $result;
 }