/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { Tecnico: create($request->all()); Session::flash('message', 'Tecnico Creado con Exito'); Redirect::to('tecnicos'); }
function cloneCategory($category, $sortId = 0) { $id = $category->id; unset($category->id); unset($category->creationtime); unset($category->wholeName); unset($category->permaLink); $category->sortId = $sortId; $category->subCatNum = $category->directSubCatNum = $category->itemNum = $category->directItemNum = 0; if (!$this->withPictures) { $category->picture = ""; } $category->create(FALSE, TRUE); // fromClone=TRUE if ($this->withPictures && $category->picture) { copy(CAT_PIC_DIR . "/{$id}.{$category->picture}", CAT_PIC_DIR . "/{$category->id}.{$category->picture}"); } // Cloning the custom fields: G::load($fields, array("SELECT * FROM @customfield WHERE cid=#cid#", $id)); foreach ($fields as $field) { unset($field->id); $field->cid = $category->id; create($field); } if ($this->recursive) { G::load($subCats, array("SELECT * FROM @category WHERE up=#id#", $id)); foreach ($subCats as $sc) { $sc->up = $category->id; $this->cloneCategory($sc, $sc->sortId); } } }
public function tokenContext() { $context = new MappedLogContext(); $context->put('key1', 'val1'); $event = new LoggingEvent(new LogCategory('default', LogLevel::ALL, $context), 1258733284, 1, LogLevel::INFO, array('Hello')); $this->assertEquals('key1=val1', create(new PatternLayout('%x'))->format($event)); }
function draw($points) { $xy = getXY($points); $map = getMap($xy['x'], $xy['y']); $set = getSet($points, $xy['x']); create($map, $set, $xy['x']); }
/** * Run the migrations. * * @return void */ public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('first_name'); $table->string('last_name'); $table->string('password', 60); $table->string('location_country'); $table->string('location_region'); $table->string('email')->unique(); $table->string('company'); $table->text('description'); $table->string('profile_picture'); $table->rememberToken(); $table->timestamps(); }); Schema: create('project_user', function (Blueprint $table) { $table->integer('project_id')->unsigned(); $table->foreign('project_id')->references('id')->on('projects')->onDelete('cascade'); $table->integer('user_id')->unsigned(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->timestamps(); }); }
private function getStream() { if (!$this->stream) { $this->stream = create(safe_open($this->filename, $this->mode)); } return $this->stream; }
/** * Close this buffer * */ public function close() { if (NULL === $this->data) { return; } // Already written // Calculate CRC32 $crc32 = create(new CRC32($this->md->digest()))->asInt32(); // Create random bytes $rand = ''; for ($i = 0; $i < 11; $i++) { $rand .= chr(mt_rand(0, 255)); } $preamble = $this->cipher->cipher($rand . chr($crc32 >> 24 & 0xff)); // Now cipher and the compress raw bytes $compressed = new MemoryOutputStream(); $compression = $this->compression[0]->getCompressionStream($compressed, $this->compression[1]); $compression->write($this->cipher->cipher($this->data->getBytes())); $bytes = $compressed->getBytes(); // Finally, write header, preamble and bytes $this->writer->writeFile($this->file, $this->size, strlen($bytes) + strlen($preamble), $crc32, 1); $this->writer->streamWrite($preamble); $this->writer->streamWrite($bytes); delete($this->data); }
function main() { dumpgen(create()); dumpgen(unusedarg(new logger(), 5)); dumpgen(getargs(1, 2, 3, 4, 5)); $g = genthrow(); try { $g->next(); } catch (Exception $e) { } try { $g->next(); } catch (Exception $e) { var_dump($e->getMessage()); } $g = manylocals(); $g->next(); var_dump($g->current()); $g->send(new stdclass()); var_dump($g->current()); $g->send($g); var_dump($g->current()); $g->next(); var_dump($g->current()); var_dump($g->valid()); }
/** * Constructor * * @param xp.compiler.io.Source source * @param xp.compiler.diagnostic.DiagnosticListener listener * @param xp.compiler.io.FileManager manager * @param xp.compiler.emit.Emitter emitter * @param util.collections.HashTable<xp.compiler.io.Source, xp.compiler.types.Types> done */ public function __construct(\xp\compiler\io\Source $source, \xp\compiler\diagnostic\DiagnosticListener $listener, \xp\compiler\io\FileManager $manager, \xp\compiler\emit\Emitter $emitter, $done = null) { $this->source = $source; $this->manager = $manager; $this->listener = $listener; $this->emitter = $emitter; $this->done = $done ?: create('new util.collections.HashTable<xp.compiler.io.Source, xp.compiler.types.Types>()'); }
public function languageNegotiation() { $supported = array('de_DE', 'en_UK', 'en_US', 'es_ES'); $default = 'en_US'; foreach (array('de_DE, en_UK' => 'de_DE', 'es_ES, de_DE' => 'es_ES', 'en_US' => 'en_US', 'fr_FR' => 'en_US', 'fr_FR, en_UK' => 'en_UK') as $usersetting => $result) { $this->assertEquals(new Locale($result), create(new LocaleNegotiator($usersetting))->getLocale($supported, $default), 'Setting <' . $usersetting . '> should yield ' . $result . ' (supported: ' . implode(', ', $supported) . ', default: ' . $default . ')'); } }
public function arrayOfStringToStringMultiple() { $l = create('new net.xp_framework.unittest.core.generics.Lookup<string[], string>'); $l->put(array('red', 'green', 'blue'), 'colors'); $l->put(array('PHP', 'Java', 'C#'), 'names'); $this->assertEquals('colors', $l->get(array('red', 'green', 'blue'))); $this->assertEquals('names', $l->get(array('PHP', 'Java', 'C#'))); }
/** * Issue a request * * @param string path The path * @param mixed[] args The arguments * @return webservices.rest.RestResponse */ protected function req($path, $args = array()) { $req = create(new RestRequest())->withHeader('Authorization', new BasicAuthorization($this->url->getUser(), $this->url->getPassword()))->withResource(rtrim($this->url->getPath(), '/') . $path)->withMethod(HttpConstants::GET); foreach ($args as $name => $value) { $req->addParameter($name, $value); } return $this->con->execute($req); }
/** * Returns the active event loop. Can be used to set the active event loop if the event loop has not been accessed. * * @param \Icicle\Loop\LoopInterface|null $loop * * @return \Icicle\Loop\LoopInterface */ function loop(LoopInterface $loop = null) : LoopInterface { static $instance; if (null === $instance || null !== $loop) { $instance = $loop ?: create(); } return $instance; }
/** * Runs the tasks set up in the given function in a separate event loop from the default event loop. If the default * is running, the default event loop is blocked while the separate event loop is running. * * @param callable $worker * @param Loop|null $loop * * @return bool */ function with(callable $worker, Loop $loop = null) : bool { $previous = loop(); try { return loop($loop ?: create())->run($worker); } finally { loop($previous); } }
/** * Send a HTTP error message * * @param peer.Socket socket * @param int sc the status code * @param string message status message * @param string reason the reason * @return int */ protected function sendErrorMessage(Socket $socket, $sc, $message, $reason) { $package = create(new \lang\XPClass(__CLASS__))->getPackage(); $errorPage = $package->providesResource('error' . $sc . '.html') ? $package->getResource('error' . $sc . '.html') : $package->getResource('error500.html'); $body = str_replace('<xp:value-of select="reason"/>', $reason, $errorPage); $this->sendHeader($socket, $sc, $message, array('Content-Type' => 'text/html', 'Content-Length' => strlen($body))); $socket->write($body); return $sc; }
/** * Sets up test case and backups Console::$err stream. * */ public function setUp() { $this->cat = create(new LogCategory('default'))->withAppender(create(new ConsoleAppender())->withLayout(newinstance('util.log.Layout', array(), '{ public function format(LoggingEvent $event) { return implode(" ", $event->getArguments()); } }'))); $this->stream = Console::$err->getStream(); }
/** * Run the migrations. * * @return void */ public function up() { Schema: create('tags', function (Blueprint $table) { $table->increments('id'); $table->string('value'); $table->timestamps(); }); }
/** * Sets up test case */ public function setUp() { $this->events = create('new util.collections.Vector<string>()'); $appender = newinstance(Appender::class, [$this->events], ['events' => null, '__construct' => function ($events) { $this->events = $events; }, 'append' => function (LoggingEvent $event) { $this->events[] = $this->layout->format($event); }]); $this->fixture = (new LogCategory('default'))->withAppender($appender->withLayout(new PatternLayout('[%l] %m'))); }
/** * @param \Icicle\File\Driver|null $driver * * @return \Icicle\File\Driver */ function driver(Driver $driver = null) : Driver { static $instance; if (null !== $driver) { $instance = $driver; } elseif (null === $instance) { $instance = create(); } return $instance; }
function main() { $resp = array(); if (isset($_POST['submit'])) { $productData = array('product_name' => isset($_POST['product_name']) ? $_POST['product_name'] : null, 'category_id' => isset($_POST['product_category']) ? (int) $_POST['product_category'] : null, 'product_is_saleable' => isset($_POST['product_is_saleable']) ? (int) $_POST['product_is_saleable'] : null, 'product_price' => isset($_POST['product_price']) ? (int) $_POST['product_price'] : null, 'product_stock' => isset($_POST['product_stock']) ? (int) $_POST['product_stock'] : null, 'product_brand' => isset($_POST['product_brand']) ? (int) $_POST['product_brand'] : null, 'product_gender' => isset($_POST['product_gender']) ? (int) $_POST['product_gender'] : null, 'product_color' => isset($_POST['product_color']) ? $_POST['product_color'] : null, 'product_cloth_type' => isset($_POST['product_cloth_type']) ? $_POST['product_cloth_type'] : null, 'product_made_in' => isset($_POST['product_made_in']) ? (int) $_POST['product_made_in'] : null, 'product_description' => isset($_POST['product_description']) ? $_POST['product_description'] : null); //TODO implement dedicated validation checks for every piece of data rather than following simple test $dataIsCorrect = true; foreach ($productData as $pieceOfData) { if (is_null($pieceOfData)) { addMessage('اطلاعات محصول به درستی وارد نشده است', FAILURE); $dataIsCorrect = false; break; } } // Handling product picture $pictureHandlingResult = handleProductPictureUpload(); if (is_string($pictureHandlingResult)) { $productData['product_picture_name'] = $pictureHandlingResult; } if ($dataIsCorrect && $pictureHandlingResult !== false && create('products', $productData)) { addMessage(sprintf('"%s" با موفقیت ایجاد شد', htmlentities($productData['product_name'], ENT_QUOTES, 'UTF-8')), SUCSESS); return array('redirect' => BASE_URL . 'admin/product/list.php'); } elseif ($dataIsCorrect) { addMessage('خطا در ذخیره سازی محصول', FAILURE); } } $tempCategories = listRecords('categories'); $categories = array(); foreach ($tempCategories as $category) { $categories[$category['id']] = $category['category_name']; } //TODO consider a table or config file for country $tempCountries = listRecords('countries'); $countries = array(); foreach ($tempCountries as $country) { $countries[$country['id']] = $country['country_name']; } /* * Load Brands */ $tempBrands = listRecords('brands'); $brands = array(); foreach ($tempBrands as $brand) { $brands[$brand['id']] = $brand['brand_name']; } //TODO consider a table for OS // $oses=array( // 1=>'Windows', // 2=>'Android', // 3=>'IOS', // 4=>'Linux' // ); $resp['data'] = array('categories' => $categories, 'brands' => $brands, 'countries' => $countries, 'productData' => isset($productData) ? $productData : array()); return $resp; }
public function map_of_string_to_object() { \lang\ClassLoader::defineClass('GenericsBCTest_Map', 'lang.Object', array(), '{ public $__generic; public function getClassName() { return "Map<".$this->__generic[0].", ".$this->__generic[1].">"; } }'); $this->assertEquals('Map<String, Object>', create('new GenericsBCTest_Map<String, Object>')->getClassName()); }
/** * Create client by inspecting the URL * * @param string url The API url * @return com.atlassian.jira.api.JiraClientProtocol */ public static function forURL($url) { $u = new URL($url); // Check for REST API client v2 if (create(new String($u->getPath()))->contains('/rest/api/2')) { return XPClass::forName('com.atlassian.jira.api.protocol.JiraClientRest2Protocol')->newInstance($u); // No suitable protocol found } else { throw new IllegalArgumentException('No suitable client found for ' . $url); } }
/** * Main runner method * * @param string[] args */ public static function main(array $args) { // Parse args $api = new RestClient('http://builds.planet-xp.net/'); $action = null; $cat = null; for ($i = 0, $s = sizeof($args); $i < $s; $i++) { if ('-?' === $args[$i] || '--help' === $args[$i]) { break; } else { if ('-a' === $args[$i]) { $api->setBase($args[++$i]); } else { if ('-v' === $args[$i]) { $cat = create(new LogCategory('console'))->withAppender(new ColoredConsoleAppender()); } else { if ('-' === $args[$i][0]) { Console::$err->writeLine('*** Unknown argument ', $args[$i]); return 128; } else { $action = $args[$i]; // First non-option is the action name break; } } } } } if (null === $action) { Console::$err->writeLine(self::textOf(\lang\XPClass::forName(\xp::nameOf(__CLASS__))->getComment())); return 1; } try { $class = \lang\reflect\Package::forName('xp.install')->loadClass(ucfirst($action) . 'Action'); } catch (\lang\ClassNotFoundException $e) { Console::$err->writeLine('*** No such action "' . $action . '"'); return 2; } // Show help if (in_array('-?', $args) || in_array('--help', $args)) { Console::$out->writeLine(self::textOf($class->getComment())); return 3; } // Perform action $instance = $class->newInstance($api); $instance->setTrace($cat); try { return $instance->perform(array_slice($args, $i + 1)); } catch (\lang\Throwable $e) { Console::$err->writeLine('*** Error performing action ~ ', $e); return 1; } }
/** * Close this buffer * */ public function close() { if (NULL === $this->data) { return; } // Already written $this->compression->close(); $bytes = $this->data->getBytes(); $this->writer->writeFile($this->file, $this->size, strlen($bytes), create(new CRC32($this->md->digest()))->asInt32(), 0); $this->writer->streamWrite($bytes); delete($this->data); }
function InsereTime_controller($objeto) { $time = array('nome' => '', 'gameTag' => '', 'whatsApp' => '', 'n_jogos' => '', 'pontos' => '', 'golsPro' => '', 'golsContra' => '', 'saldoGols' => ''); $time['nome'] = $objeto->getNome(); $time['gameTag'] = $objeto->getGametag(); $time['whatsApp'] = $objeto->getWhatsApp(); $time['n_jogos'] = $objeto->getN_jogos(); $time['golsPro'] = $objeto->getPontos(); $time['golsContra'] = $objeto->getGolsContra(); $time['saldoGols'] = $objeto->getSaldoGols(); create('times', $time); }
/** * Constructor */ public function __construct() { $this->mappers = create('new util.collections.HashTable<lang.XPClass, webservices.rest.srv.ExceptionMapper>'); $this->marshalling = new RestMarshalling(); // Default exception mappings $this->addExceptionMapping('lang.IllegalAccessException', new DefaultExceptionMapper(403)); $this->addExceptionMapping('lang.IllegalArgumentException', new DefaultExceptionMapper(400)); $this->addExceptionMapping('lang.IllegalStateException', new DefaultExceptionMapper(409)); $this->addExceptionMapping('lang.ElementNotFoundException', new DefaultExceptionMapper(404)); $this->addExceptionMapping('lang.MethodNotImplementedException', new DefaultExceptionMapper(501)); $this->addExceptionMapping('lang.FormatException', new DefaultExceptionMapper(422)); $this->addMarshaller('lang.Throwable', new DefaultExceptionMarshaller()); }
/** * Helper method * * @param xml.Node starting node * @param string tagname * @return util.collections.Vector<xml.Node> */ protected function getElementsByTagName($node, $tagname) { $r = create('new util.collections.Vector<xml.Node>()'); foreach (array_keys($node->getChildren()) as $key) { if ($tagname == $node->nodeAt($key)->getName()) { $r[] = $node->nodeAt($key); } if ($node->nodeAt($key)->hasChildren()) { $r->addAll($this->_getElementsByTagName($node->nodeAt($key), $tagname)); } } return $r; }
/** * Constructor */ public function __construct() { $this->mappers = create('new HashTable<XPClass, ExceptionMapper>'); $this->marshallers = create('new HashTable<Type, TypeMarshaller>'); // Default exception mappings $this->addExceptionMapping('lang.IllegalAccessException', new DefaultExceptionMapper(403)); $this->addExceptionMapping('lang.IllegalArgumentException', new DefaultExceptionMapper(400)); $this->addExceptionMapping('lang.IllegalStateException', new DefaultExceptionMapper(409)); $this->addExceptionMapping('lang.ElementNotFoundException', new DefaultExceptionMapper(404)); $this->addExceptionMapping('lang.MethodNotImplementedException', new DefaultExceptionMapper(501)); $this->addExceptionMapping('lang.FormatException', new DefaultExceptionMapper(422)); $this->addMarshaller('lang.Throwable', new DefaultExceptionMarshaller()); }
/** * Execute this action * * @param string[] $args command line args * @return int exit code */ public function perform($args) { $request = create(new RestRequest('/search'))->withParameter('q', $args[0]); $total = 0; Console::writeLine('@', $this->api->getBase()->getURL()); $results = $this->api->execute($request)->data(); foreach ($results as $result) { Console::writeLine(new Module($result['vendor'], $result['module']), ': ', $result['info']); $total++; } Console::writeLine(); Console::writeLine($total, ' modules(s) found.'); return 0; }
public function information() { $p = new Process($this->executable(), array('-v')); try { $this->assertEquals(-1, $p->exitValue(), 'Process should not have exited yet'); $this->assertNotEquals(0, $p->getProcessId()); $this->assertNotEquals('', $p->getFilename()); $this->assertTrue(create(new \lang\types\String($p->getCommandLine()))->contains('-v')); $p->close(); } catch (\unittest\AssertionFailedError $e) { $p->close(); // Ensure process is closed throw $e; } }