public static function register($eventName, array $options = [], array $content = []) { // Add the email event to the collection if it isn't already $event = (new static())->setCondition('event_name', $eventName)->getItem(); if (empty($event->id)) { try { $event = new static(); $event->bind(array('event_name' => $eventName))->bind($options)->bind($content)->save(); // create the first template? /* * $content = $content + ['title' => 'Default', 'copy' => 'Default From Application']; * $model = (new \Mailer\Models\Templates); * $model->set('event_id',$event->id); * $model->bind($content); * $model->save(); */ return $event; } catch (\Exception $e) { echo $e->getMessage(); die; return false; } } else { // update the default values for the event $event->bind($options)->bind($content)->save(); } return true; }
/** * @param array $data * @return static */ public static function insert(array $data = [], $ignore = false) { /** @var Table $model */ $model = new static(); $model->bind($data)->save($ignore); return $model; }
public static function raw($sql, $binds = [], $part = 'main') { $query = new static($sql); foreach ($binds as $bind) { $query->bind($bind, $part); } return $query; }
/** * Create a new Irto\OAuth2Proxy\Server instance with $config * * @param array $config * * @return Irto\OAuth2Proxy\Server */ public static function create(array $config) { $server = new static(); isset($config['verbose']) && $server->setVerbose($config['verbose']); $server->singleton('config', function ($server) use($config) { return new Collection($config); }); $server->bind('Irto\\OAuth2Proxy\\Server', function ($server) { return $server; }); // Create main loop React\EventLoop based $server->singleton('React\\EventLoop\\LoopInterface', function ($server) { return React\EventLoop\Factory::create(); }); // DNS resolve, used for create async requests $server->singleton('React\\Dns\\Resolver\\Resolver', function ($server) { $dnsResolverFactory = new React\Dns\Resolver\Factory(); return $dnsResolverFactory->createCached('8.8.8.8', $server['React\\EventLoop\\LoopInterface']); //Google DNS }); // HTTP Client $server->singleton('React\\HttpClient\\Client', function ($server) { $factory = new React\HttpClient\Factory(); return $factory->create($server['React\\EventLoop\\LoopInterface'], $server['React\\Dns\\Resolver\\Resolver']); }); // Request handler to React\Http $server->singleton('React\\Socket\\Server', function ($server) { $socket = new React\Socket\Server($server['React\\EventLoop\\LoopInterface']); $socket->listen($server->get('port')); return $socket; }); // HTTP server for handle requests $server->singleton('React\\Http\\Server', function ($server) { return new React\Http\Server($server['React\\Socket\\Server']); }); // HTTP server for handle requests $server->singleton('SessionHandlerInterface', function ($server) { return $server->make('Irto\\OAuth2Proxy\\Session\\AsyncRedisSessionHandler', ['lifetime' => array_get($server['config']->all(), 'session.lifetime')]); }); $server->bind('Illuminate\\Session\\Store', 'Irto\\OAuth2Proxy\\Session\\Store'); $server->boot(); return $server; }
public static function register($namespace, array $options = array()) { $item = (new static())->setState('filter.namespace', $namespace)->getItem(); if (empty($item->id) || !empty($options['__update'])) { try { if (empty($item->id)) { $item = new static(); } $item->bind(array('namespace' => $namespace))->bind($options)->save(); return $item; } catch (\Exception $e) { return false; } } return true; }
public static function register($namespace, array $options = array()) { // Add the report to the collection if it isn't already $report = (new static())->setState('filter.namespace', $namespace)->getItem(); if (empty($report->id) || !empty($options['__update'])) { try { if (empty($report->id)) { $report = new static(); } $report->bind(array('namespace' => $namespace))->bind($options)->save(); return $report; } catch (\Exception $e) { return false; } } return true; }
/** * Execute * @param string $binPath Binpath * @param callable $cb Callback * @param array $args Optional. Arguments * @param array $env Optional. Hash of environment's variables */ public static function exec($binPath = null, $cb = null, $args = null, $env = null) { $o = new static(); $data = ''; $o->bind('read', function ($o) use(&$data, $o) { $data .= $o->readUnlimited(); }); $o->bind('eof', function ($o) use(&$data, $cb) { call_user_func($cb, $o, $data); $o->close(); }); $o->execute($binPath, $args, $env); }
/** * Creates an asset directly from a URL * and send it directly to S3 * * @param string $url * @param array $options * @throws \Exception */ public static function createFromUrlToS3($url, $options = array()) { $app = \Base::instance(); $s3_options = array('clientPrivateKey' => $app->get('aws.clientPrivateKey'), 'serverPublicKey' => $app->get('aws.serverPublicKey'), 'serverPrivateKey' => $app->get('aws.serverPrivateKey'), 'expectedBucketName' => $app->get('aws.bucketname'), 'expectedMaxSize' => $app->get('aws.maxsize'), 'cors_origin' => $app->get('SCHEME') . "://" . $app->get('HOST') . $app->get('BASE')); if (!class_exists('\\Aws\\S3\\S3Client') || empty($s3_options['clientPrivateKey']) || empty($s3_options['serverPublicKey']) || empty($s3_options['serverPrivateKey']) || empty($s3_options['expectedBucketName']) || empty($s3_options['expectedMaxSize'])) { throw new \Exception('Invalid configuration settings'); } $options = $options + array('width' => 460, 'height' => 308); $request = \Web::instance()->request($url); if (empty($request['body'])) { throw new \Exception('Could not download asset from provided URL'); } $model = new static(); $url_path = parse_url($url, PHP_URL_PATH); $pathinfo = pathinfo($url_path); $filename = $model->inputfilter()->clean($url_path); $buffer = $request['body']; $originalname = str_replace("/", "-", $filename); $thumb = null; if ($thumb_binary_data = $model->getThumb($buffer, null, $options)) { $thumb = new \MongoBinData($thumb_binary_data, 2); } $title = \Dsc\String::toSpaceSeparated($model->inputFilter()->clean($originalname)); $values = array('storage' => 's3', 'contentType' => $model->getMimeType($buffer), 'md5' => md5($filename), 'thumb' => $thumb, 'url' => null, "source_url" => $url, "filename" => $filename, 'title' => $title); $model->bind($values); // these need to happen after the bind $model->slug = $model->generateSlug(); $model->_id = new \MongoId(); /** * Push to S3 */ $bucket = $app->get('aws.bucketname'); $s3 = \Aws\S3\S3Client::factory(array('key' => $app->get('aws.serverPublicKey'), 'secret' => $app->get('aws.serverPrivateKey'))); $key = (string) $model->_id; $res = $s3->putObject(array('Bucket' => $bucket, 'Key' => $key, 'Body' => $buffer, 'ContentType' => $model->contentType)); $s3->waitUntil('ObjectExists', array('Bucket' => $bucket, 'Key' => $key)); if (!$s3->doesObjectExist($bucket, $key)) { throw new \Exception("Upload to Amazon S3 failed"); } $objectInfoValues = $s3->headObject(array('Bucket' => $bucket, 'Key' => $key))->getAll(); /** * END Push to S3 */ $model->url = $s3->getObjectUrl($bucket, $key); $model->s3 = array_merge(array(), (array) $model->s3, array('bucket' => $bucket, 'key' => $key, 'uuid' => (string) $model->_id)) + $objectInfoValues; return $model->save(); }