method add documentation in bbn\Cdn\Library

Adds a new library to the config.

Example

// @var bbn\Cdn\Library $lib $lib->add('jquery-ui') // jQuery will be added too ->add('axios', false); // no dependency will be added here X::dump($lib->getConfig()); // { // "libraries": { // "jquery": "3.3.1", // "jquery-ui": "1.12.1", // "axios": "v0.19.2", // }, // "prepend": [ // ], // "js": [ // "lib/jquery/3.3.1/dist/jquery.min.js", // "lib/jquery-ui/1.12.1/jquery-ui.min.js", // "lib/axios/v0.19.2/dist/axios.min.js", // ], // "css": [ // "lib/jquery-ui/1.12.1/jquery-ui.min.css", // ], // } function(string $library, $has_dep = 1) { if ($info = $this->info($library)) { if (!isset($this->libs[$info['name']][$info['internal']])) { $last = $this->db->last(); if ($has_dep) { // Adding dependencies if (!$info['id']) { throw new \Exception(X::_("Problem adding library").' '.$library); } $dependencies = $this->getDependencies($info['id']); //X::dump($dependencies, $info); if (!empty($dependencies)) { foreach ($dependencies as $dep) { $this->add($dep); } } } if (!isset($this->libs[$info['name']])) { $this->libs[$info['name']] = []; } $path = 'lib/'.$info['name'].'/'.$info['version'].'/'; $this->libs[$info['name']][$info['internal']] = [ 'version' => $info['version'], 'prepend' => [], 'git' => $info['git'], 'npm' => $info['npm'], 'mode' => $info['mode'], 'name' => $info['name'], 'fname' => $info['fname'], 'path' => $path, 'files' => [] ]; $files =& $this->libs[$info['name']][$info['internal']]['files']; $prepend =& $this->libs[$info['name']][$info['internal']]['prepend']; // From here, adding files (no matter the type) to $this->libs array for each library // Adding language files if they must be prepent if (($this->lang !== 'en') && isset($info['content']->lang, $info['content']->prepend_lang)) { foreach ($info['content']->lang as $lang) { $files[] = sprintf($path.$lang, $this->lang); } } if (isset($info['content']->files) && is_array($info['content']->files)) { // Adding each files - no matter the type foreach ($info['content']->files as $f) { if (isset($this->info['theme']) && strpos($f, '%s')) { $f = sprintf($f, $this->info['theme']); } if (isset($info['prepend'][$f])) { $prepend[$path.$f] = []; foreach ($info['prepend'][$f] as $p) { $prepend[$path.$f][] = $path.$p; } } $files[] = $path.$f; } } else { throw new \Exception("No file to add for the library $library"); } // Adding language files at the end (default way) if (($this->lang !== 'en') && isset($info['content']->lang) && !isset($info['content']->prepend_lang)) { if (is_string($info['content']->lang)) { $info['content']->lang = [$info['content']->lang]; } if (is_array($info['content']->lang)) { foreach ($info['content']->lang as $lang) { array_push($files, sprintf($path.$lang, $this->lang)); } } else { die("Problem with the language file for $info[name]"); } } } } else { throw new \Exception("Impossible to retrieve information on library $library"); } return $this; }

Adds a new library to the config. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.