예제 #1
0
 /**
  * Fire a task in background using Beanstalkd
  *
  * @param $job Illuminate\Queue\Jobs\BeanstalkdJob
  * @param $data array
  *
  * @return void
  */
 public static function fire($job, $data)
 {
     \Log::info('Queue job called #' . $job->getJobId(), Arr::toArray($data));
     $method = $data['@method'];
     unset($data['@method']);
     $t = self::getInstance();
     call_user_func_array(array($t, $method), $data);
     $job->delete();
 }
예제 #2
0
 public static function config($param = array())
 {
     $default = array('driver' => 'smtp', 'host' => getenv('SERVER_NAME'), 'port' => 25, 'from' => array('address' => 'no-reply@' . getenv('SERVER_NAME'), 'name' => 'No Reply'), 'encryption' => 'tls', 'username' => '', 'password' => '', 'sendmail' => '/usr/sbin/sendmail -bs', 'pretend' => false);
     $config = Arr::merge($default, $param);
     $t = self::getInstance();
     switch ($config['driver']) {
         case 'smtp':
             extract($config);
             // The Swift SMTP transport instance will allow us to use any SMTP backend
             // for delivering mail such as Sendgrid, Amazon SMS, or a custom server
             // a developer has available. We will just pass this configured host.
             $transport = SmtpTransport::newInstance($config['host'], $config['port']);
             if (isset($config['encryption'])) {
                 $transport->setEncryption($config['encryption']);
             }
             // Once we have the transport we will check for the presence of a username
             // and password. If we have it we will set the credentials on the Swift
             // transporter instance so that we'll properly authenticate delivery.
             if (isset($username)) {
                 $transport->setUsername($config['username']);
                 $transport->setPassword($config['password']);
             }
             $t->_transport = $transport;
             break;
         case 'sendmail':
             $t->_transport = SendmailTransport::newInstance($config['sendmail']);
             break;
         case 'mail':
             $t->_transport = MailTransport::newInstance();
             break;
         default:
             throw new \InvalidArgumentException('Invalid mail driver.');
     }
     $t->_mailer = Swift_Mailer::newInstance($t->_transport);
     return $t;
 }
예제 #3
0
 /**
  * Upload method helper
  *
  * @param null $name
  * @param null $file
  * @param array $params
  * @return array
  * @throws Exception
  */
 public function upload($name = null, $file = null, $params = ['afterUpload' => null, 'beforeUpload' => null, 'coords' => null, 'width' => null, 'height' => null, 'beforeUploadImage' => null])
 {
     Arr::mergeWithDefaultParams($params);
     $data = [];
     if ($file) {
         $data['file'] = $file;
     } elseif (Input::hasFile('file')) {
         $data['file'] = Input::file('file');
     } else {
         trigger_error("File doesn't exist.");
     }
     $data['name'] = $name;
     $data['params'] = $params;
     $data['response'] = false;
     $data['path'] = $this->relPath();
     $data['fullname'] = $data['file']->getClientOriginalName();
     $data['extension'] = $data['file']->getExtension();
     $data['mimeType'] = $data['file']->getMimeType();
     if (in_array($data['mimeType'], ['image/gif', 'image/jpeg', 'image/png'])) {
         $data['type'] = "image";
     } else {
         $data['type'] = "file";
     }
     if (!$data['name']) {
         $data['name'] = $data['file']->getClientOriginalName();
     } elseif (!preg_match('/\\.' . $data['extension'] . '$/i', $data['name'])) {
         $data['convert'] = true;
     } elseif (!preg_match('/\\./i', $data['name'])) {
         $data['name'] .= $data['name'] . '.' . $data['extension'];
     }
     if ($params['beforeUpload']) {
         $data = $params['beforeUpload']($data);
     }
     if ($data['type'] == 'image') {
         $img = Image::load($data['file']->getRealPath());
         if ($data['params']['coords']) {
             $coords = $data['params']['coords'];
             if (!is_array($coords)) {
                 $coords = json_decode(stripslashes($coords), true);
             }
             $img->crop($coords['x'], $coords['y'], $coords['x'] + $coords['w'], $coords['y'] + $coords['h']);
         } elseif ($data['params']['width'] && $data['params']['height']) {
             $img->resize($data['params']['width'], $data['params']['height']);
         } elseif ($data['params']['width']) {
             $img->fit_to_width($data['params']['width']);
         } elseif ($data['params']['height']) {
             $img->fit_to_width($data['params']['height']);
         }
         if ($params['beforeUploadImage']) {
             $img = $params['beforeUploadImage']($img);
         }
         @mkdir($data['path'], null, true);
         $data['response'] = $img->save(public_path($data['path'] . $data['name']));
     } else {
         $data['response'] = File::move($data['file']->getRealPath(), $data['path'] . $data['name']);
     }
     if ($params['afterUpload']) {
         $data = $params['afterUpload']($data);
     }
     return $data;
 }
예제 #4
0
 /**
  * Set the flash element
  *
  * @param $options
  * @param $settings
  * @return $this
  */
 public function set($options = ['icon' => null, 'title' => null, 'message' => '', 'url' => null, 'target' => null], $settings = [])
 {
     $settings = Arr::merge($this->settings, $settings);
     $this->session->flash('notify.options', $options);
     $this->session->flash('notify.settings', $settings);
     $this->hook->put('__app.notify.options', $options);
     $this->hook->put('__app.notify.settings', $settings);
     return $this;
 }
예제 #5
0
 public function toJson()
 {
     return Arr::toJson($this->_values);
 }
 /**
  * Clean path handler
  *
  * @param $path
  * @param array $params
  * @return mixed
  * @throws Exception
  */
 public static function cleanPath($path, $params = ['checkDir' => false, 'checkFile' => false])
 {
     $params = Arr::mergeWithDefaultParams($params);
     if ($params['checkDir']) {
         if (!is_dir($path)) {
             throw new Exception('Path is not a dir');
         }
     }
     if ($params['checkFile']) {
         if (!is_file($path)) {
             throw new Exception('Path is not a file');
         }
     }
     return str_replace(array('//'), array('/'), $path);
 }
예제 #7
0
 /**
  * Set value in $_settings
  *
  * @param string $sName  Array of new value or name
  * @param mixed  $mValue Value for name
  *
  * @return object
  *
  * @example
  * Config::instance()->set(array('defaults.somehing' => 'something'));
  * Config::instance()->set('defaults.something', 'something');
  */
 public static function set($sName, $mValue = null)
 {
     if (is_array($sName)) {
         foreach ($sName as $key => $value) {
             Arr::set(static::$aSettings, $key, $value);
         }
     } else {
         Arr::set(static::$aSettings, $sName, $mValue);
     }
     return static::getInstance();
 }
예제 #8
0
 /**
  * Set body attributes
  */
 public function setBodyAttributes($layout, $data = array())
 {
     $data = Arr::merge($data, array('body' => array('attributes' => array('class' => static::$tplPrefixClass . str_replace(array('::', '.'), '-', $layout)))));
     $data = $this->getCommonVars($data);
     view()->share('body', $data['body']);
     return $data;
 }
예제 #9
0
 /**
  * Transform any value to Array
  *
  * @param $mValue
  * @return mixed
  */
 public static function toArray($mValue)
 {
     return Arr::toArray($mValue);
 }
예제 #10
0
 /**
  * Create a text input field.
  *
  * @param string $name
  * @param string $value
  * @param array $options
  * @return string
  * @static
  */
 public static function text($name, $value = null, $options = array())
 {
     $defOptions = array('class' => 'form-control');
     $options = Arr::merge($defOptions, $options);
     return self::resolve($name, $value, $options);
 }
예제 #11
0
 /**
  * Add a bootstrap btn helper
  *
  * @param $href
  * @param $content
  * @param array $attr
  * @param array $params
  * @return string
  * @throws \Exception
  */
 public static function btn($href, $content, $attr = ['class' => 'btn btn-default'], $params = array('tag' => 'a', 'attrHref' => 'href'))
 {
     $params = Arr::mergeWithDefaultParams($params);
     if (preg_match('/^fa-/', $content)) {
         $content = "<i class=\"fa " . $content . '"></i>';
     } elseif (preg_match('/^glyphicon-/', $content)) {
         $content = "<i class=\"glyphicon " . $content . '"></i>';
     }
     return '<' . $params['tag'] . ' ' . $params['attrHref'] . '="' . $href . '" ' . Html::attributes($attr) . '>' . $content . '</' . $params['tag'] . '>';
 }
예제 #12
0
 /**
  * Same than View make but injects common vars
  *
  * @param $layout
  * @param array $data
  * @return \Illuminate\View\View
  */
 public function viewMake($layout, $data = array())
 {
     $data = Arr::merge($data, array('body' => array('attributes' => array('class' => static::$tplPrefixClass . str_replace(array('::', '.'), '-', $layout)))));
     $data = $this->getCommonVars($data);
     return View::make($layout, $data);
 }
예제 #13
0
파일: Db.php 프로젝트: SerdarSanri/arx-core
 public static function configMysql($param = array())
 {
     $default = array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '');
     return Arr::merge($default, $param);
 }