public function convert($fv, $fc, $tc) { using('lepton.web.forex'); $cc = new CurrencyExchange(); $tv = $cc->convert($fv, $fc, $tc); console::writeLn("%0.2f %s = %0.2f %s", $fv, $fc, $tv, $tc); }
function test_using_two_disponsables_with_exceptions_calling_both_disposes() { $disposeCalled = ['foo' => false, 'bar' => false]; $foo = $this->getMockBuilder('Foo')->getMock(); $foo->expects($this->any())->method('dispose')->will($this->returnCallback(function () use(&$disposeCalled) { $disposeCalled['foo'] = true; })); $foo->expects($this->any())->method('hello')->will($this->returnCallback(function () { throw new \Exception('hello function exception'); })); $bar = $this->getMockBuilder('Bar')->getMock(); $bar->expects($this->any())->method('dispose')->will($this->returnCallback(function () use(&$disposeCalled) { $disposeCalled['bar'] = true; })); $this->assertFalse($disposeCalled['foo'], 'Foo dispose has been called'); $this->assertFalse($disposeCalled['bar'], 'Bar dispose has been called'); try { using([$foo, $bar], function (Foo $foo, Bar $bar) { $foo->hello("Gonzalo"); $bar->hello("Gonzalo"); }); } catch (\Exception $e) { } $this->assertTrue($disposeCalled['foo'], 'Foo dispose has been called'); $this->assertTrue($disposeCalled['bar'], 'Bar dispose has been called'); }
function __construct() { using('lepton.web.captcha'); using('lepton.mvc.request'); using('lepton.mvc.response'); using('lepton.mvc.session'); }
/** * @description Service Discovery */ function discover() { using('lepton.net.httprequest'); using('lepton.web.discovery'); $d = Discovery::discover('http://127.0.0.1'); $this->assertNotNull($d); }
function detail() { global $G; using("area", "industry"); $area = new Areas(); $industry = new Industries(); $tpl_file = "company/detail"; $this->viewhelper->setTitle(L("yellow_page", "tpl")); $this->viewhelper->setPosition(L("yellow_page", "tpl"), "index.php?do=company"); if (isset($_GET['id'])) { $id = intval($_GET['id']); $result = $area->dbstuff->GetRow("SELECT * FROM {$area->table_prefix}companies WHERE id='" . $id . "'"); if (!empty($result)) { $login_check = 1; //default open if (isset($G['setting']['company_logincheck'])) { $login_check = $G['setting']['company_logincheck']; } $this->viewhelper->setTitle($result['name']); $this->viewhelper->setPosition($result['name']); $result['tel'] = pb_hidestr(preg_replace('/\\((.+?)\\)/i', '', $result['tel'])); $result['fax'] = pb_hidestr(preg_replace('/\\((.+?)\\)/i', '', $result['fax'])); $result['mobile'] = pb_hidestr($result['mobile']); $result['industry_names'] = $industry->disSubNames($result['industry_id'], null, true, "company"); $result['area_names'] = $area->disSubNames($result['area_id'], null, true, "company"); setvar("item", $result); setvar("LoginCheck", $login_check); } } render($tpl_file, 1); }
/** * Magic Start method. When this method is invoked the job is to pick up * where it left off and resume or start the processing of the job. */ function start() { $this->setState(LdwpJob::STATE_RUNNING, 0, 1, "Downloading " . $this->url); using('lepton.net.httprequest'); $dl = new HttpRequest($this->url, array('saveto' => $this->destination, 'onprogress' => new Callback($this, 'onDownloadProgress'))); $this->setState(LdwpJob::STATE_COMPLETED, 1, 1, "Saved " . $this->url); }
function broke() { foreach (using(function () { (yield 1); (yield 2); (yield 3); }) as $x) { var_dump($x); } }
protected function findClass($classpath) { if (strpos($classpath, '.') !== false) { using($classpath); $class = explode('.', $classpath); return $class[count($class) - 1]; } else { return $classpath; } }
function lists() { global $viewhelper, $pos; using("industry", "area"); $area = new Areas(); $industry = new Industries(); $conditions[] = "Job.status=1"; $viewhelper->setTitle(L("hr_information", "tpl")); $viewhelper->setPosition(L("hr_information", "tpl"), "index.php?do=job&action=" . __FUNCTION__); if (!empty($_GET['q'])) { $title = trim($_GET['q']); $conditions[] = "Job.name like '%" . $title . "%'"; } if (!empty($_GET['data']['salary_id'])) { $conditions[] = "Job.salary_id=" . intval($_GET['data']['salary_id']); } if (!empty($_GET['data']['area_id'])) { $conditions[] = "Job.area_id=" . intval($_GET['data']['area_id']); } if (isset($_GET['industryid'])) { $industry_id = intval($_GET['industryid']); $tmp_info = $industry->setInfo($industry_id); if (!empty($tmp_info)) { $conditions[] = "Job.industry_id=" . $tmp_info['id']; $viewhelper->setTitle($tmp_info['name']); $viewhelper->setPosition($tmp_info['name'], "index.php?do=job&action=" . __FUNCTION__ . "&industryid=" . $tmp_info['id']); } } if (isset($_GET['areaid'])) { $area_id = intval($_GET['areaid']); $tmp_info = $area->setInfo($area_id); if (!empty($tmp_info)) { $conditions[] = "Job.area_id=" . $tmp_info['id']; $viewhelper->setTitle($tmp_info['name']); $viewhelper->setPosition($tmp_info['name'], "index.php?do=job&action=" . __FUNCTION__ . "&areaid=" . $tmp_info['id']); } } $amount = $this->job->findCount(null, $conditions, "Job.id"); $result = $this->job->findAll("Job.*,Job.cache_spacename AS userid,Job.created AS pubdate,(select Company.name from " . $this->job->table_prefix . "companies Company where Company.id=Job.id) AS companyname", null, $conditions, "Job.id DESC", $pos, $this->displaypg); $viewhelper->setTitle(L("search", "tpl")); $viewhelper->setPosition(L("search", "tpl")); setvar("items", $result); setvar("paging", array('total' => $amount)); render("job/list", 1); }
function add() { global $smarty; using("message"); $pms = new Messages(); if (isset($_POST['do']) && !empty($_POST['friendlink'])) { pb_submit_check('friendlink'); $data = $_POST['friendlink']; $result = false; $data['status'] = 0; $data['created'] = $data['modified'] = $this->friendlink->timestamp; $result = $this->friendlink->save($data); if ($result) { $pms->SendToAdmin('', array("title" => $data['title'] . L("apply_friendlink"), "content" => $data['title'] . L("apply_friendlink") . "\n" . $_POST['data']['email'] . "\n" . $data['description'])); flash('wait_apply'); } } else { flash(); } }
static function request($event, $data) { $qurl = $data['uri']; if (url($qurl)->like('/^\\/sts-rpc[\\/]?/')) { using('s2s.request'); $cmd = request::get('cmd'); $req = new S2SRequest(S2SRequest::RT_HTTP, $cmd, request::getAll()); $res = new S2SResponse(S2SRequest::RT_HTTP, $cmd); $cmdp = explode('.', $cmd); $mod = $cmdp[0]; $modc = $mod . 'S2SEndpoint'; if (class_exists($modc)) { $ci = new $modc(); $rd = $ci->invoke($req, $res); var_dump($rd); } else { printf("Bad endpoint"); } return true; } return false; }
<?php config::def('lepton.gallery.mediadir', base::appPath() . '/media/'); config::def('lepton.gallery.cachedir', base::appPath() . '/cache/'); // config::def('lepton.gallery.renderer', array('WatermarkImageFilter','mylogo.png')); using('lepton.graphics.canvas'); using('lepton.utils.pagination'); class GalleryItemsTable extends SqlTableSchema { function define() { // Only to be used during testing! $this->dropOnCreate(); // Table name $this->setName('galleryitems'); // Table columns $this->addColumn('id', 'int', self::COL_AUTO | self::KEY_PRIMARY); $this->addColumn('name', 'varchar:160'); $this->addColumn('uuid', 'char:37', self::COL_FIXED); $this->addColumn('src', 'varchar:200'); // Indexes $this->addIndex('uuidkey', array('uuid'), self::KEY_UNIQUE); $this->addIndex('srckey', array('src'), self::KEY_UNIQUE); } } SqlTableSchema::apply(new GalleryItemsTable()); /** * @class Gallery * @package lepton.media * @brief Gallery Management *
<?php using('lepton.system.threading'); interface ILdwpTransport { function connect($uri); function getQueue(); function getJob($jobid); } abstract class LdwpTransport implements ILdwpTransport { static function factory($uri) { // } function connect($uri) { } function getQueue() { } function getJob($jobid) { } } class LdwpLocalTransport extends LdwpTransport { } class LdwpHttpTransport extends LdwpTransport { }
function __construct($label,$key,array $options = null) { using('lepton.web.captcha'); $this->setKey($key); $this->label = $label; parent::__construct($options); $this->captchaid = Captcha::generate(); }
function __construct() { using('lepton.utils.streams'); }
<?php using('xsnp.utils'); using('lepton.utils.prefs'); using('lepton.web.xmlrpc'); using('lepton.crypto.uuid'); class XsnpServer { private $extensions; function __construct() { $this->loadExtensions(); } private function loadExtensions() { $desc = getDescendants('XsnpServerExtension'); foreach ($desc as $dc) { $this->extensions[] = new $dc($this); } } public function handleRequest($requestdata) { // Go through the extensions and decide which one is to handle it } function xmlrpcRequest() { $xr = new XmlrpcServer(); if ($this->conf->interactenable != true) { $xr->sendError(0, 'Function Disabled'); return; }
<?php module("RGB Color Space Routines"); using('lepton.graphics.colorspace'); using('lepton.graphics.graphics'); class RgbColor extends Color { private $red; private $green; private $blue; private $alpha; /** * Constructor. This method will accept parameters in a number of * different formats: * (R,G,B) red, green, and blue (0-255) * (R,G,B,A) red, green, blue and alpha(0-255) * #RGB rgb, as a hexadecimal string (0-F) * #RRGGBB rgb, as a hexadecimal string (00-FF) * #RRGGBBAA rgba, as a hexidecimal string (00-FF) */ function __construct() { $args = func_get_args(); switch (func_num_args()) { case 0: $red = 0; $green = 0; $blue = 0; $alpha = 255; break; case 1:
<?php using('lunit.*'); using('lepton.content.*'); class DummyContentExtension extends ContentExtension { private $object; function getHandle() { return 'dummy'; } function __construct($object = null) { $this->object = $object; } function reverse() { $data = $this->object->getHtml(); $datao = ''; for ($n = strlen($data) - 1; $n >= 0; $n--) { $datao = $datao . $data[$n]; } return $datao; } } class DummyContentObject extends ContentObject { private $id; function __construct($id) { $this->id = $id;
<?php module("Console application base files"); // Console applications or services shouldn't time out set_time_limit(0); using('lepton.cli.debug'); using('lepton.cli.exception'); using('lepton.system.process'); using('lepton.cli.ansi'); logger::registerFactory(new ConsoleLoggerFactory()); abstract class AppBaseList implements IteratorAggregate, ArrayAccess { protected $data; public function __construct() { $this->data = array(); } public function getData() { return $this->data; } public function getIterator() { return new ArrayIterator($this->data); } public function offsetSet($offset, $value) { if (is_null($offset)) { $this->data[] = $value; } else { $this->data[$offset] = $value;
<?php using('lepton.geo.geo'); /** * * * @todo Make this class extendable with various APIs including maxmind's * geoIp. * * 'geoplugin_city' => 'Hammarö', * 'geoplugin_region' => 'Värmlands Län', * 'geoplugin_areaCode' => '0', * 'geoplugin_dmaCode' => '0', * 'geoplugin_countryCode' => 'SE', * 'geoplugin_countryName' => 'Sweden', * 'geoplugin_continentCode' => 'EU', * 'geoplugin_latitude' => '59.333301544189', * 'geoplugin_longitude' => '13.516699790955', * 'geoplugin_regionCode' => '22', * 'geoplugin_regionName' => 'Värmlands Län', * 'geoplugin_currencyCode' => 'SEK', * 'geoplugin_currencySymbol' => 'kr', * 'geoplugin_currencyConverter' => 6.2286000252, */ class GeopluginResolver { const API_QUERY_URL = 'http://www.geoplugin.net/php.gp?ip=%s'; static function getInformationFromIp($ip) { $data = unserialize(file_get_contents(sprintf(self::API_QUERY_URL, $ip))); foreach ($data as $k => $v) {
throw new UserException("Unassociated user id / Integrity failure", UserException::ERR_USER_UNASSOCIATED); } if (!$u->active) { throw new UserException("User is not active, check audit log", UserException::ERR_USER_INACTIVE); } // TODO: Assign to session if (ModuleManager::has('lepton.mvc.session')) { session::set(User::KEY_USER_AUTH, $id); } if (class_exists('request')) { $db = new DatabaseConnection(); $db->updateRow("UPDATE users SET lastlogin=NOW(), lastip=%s WHERE id=%d", request::getRemoteIp(), $id); } if (class_exists('UserEvents')) { event::invoke(UserEvents::EVENT_USER_LOGIN, array('id' => $id)); } } /** * @brief Clear the active user. * */ protected function clearUser() { User::clearUser(); } } using('lepton.user.user'); using('lepton.user.userrecord'); using('lepton.user.backends.*'); using('lepton.user.providers.*');
<?php require 'sys/base.php'; // The ACL and Authentication classes ar eneeded to get access to the user // record (subject) and the actual ACL classes. using('lepton.user.acl'); using('lepton.user.authentication'); /* * This is an example of how to implement the IAclObject interface. It should * not be used as it is, but rather implemented in a similar fashion. The * important thing to make sure that each instance is assigned a unique and * constant uuid. */ class Guestbook implements IAclObject { // This objects UUID private $uuid = null; // This objects defined roles private $roles = array('post' => true, 'moderate' => false, 'view' => true, 'attach' => false); function getObjectUuid() { // return the UUID of the object here return $this->uuid; } function getObjectRoles() { // return the ACL roles of the object here return $this->roles; } function getDescription() {
<?php class DatabaseException extends Exception { } using('lepton.ldb.databaseconnectionpool'); using('lepton.ldb.drivers.*'); abstract class QueryAttributes { const QATTR_GET_ASSOC = 0x1; const QATTR_GET_NUMERIC = 0x2; } class DatabaseConnection { private $conn = null; private $driver = null; private $attribs = null; /** * * @param string $group The database group to connect to or the config array */ public function __construct($connectionstring = null) { if ($connectionstring == null) { $connectionstring = 'default'; } if (is_a($connectionstring, 'DatabaseDriver')) { $this->conn = $connectionstring; logger::debug('%s: Reusing connection...', __CLASS__); return; }
/** * Loads a module instance. * This method will create a module instance or load it from memory. * @param string the module ID (must be defined in app spec) * @return TModule the module instance. * @throw TModuleNotDefinedException */ public function loadModule($name) { if (isset($this->modules[$name])) { return $this->modules[$name]; } if (!isset($this->moduleSpecs[$name])) { throw new TModuleNotDefinedException($name); } foreach ($this->moduleSpecs[$name][2] as $namespace) { using($namespace); } $this->cacheManager->setCurrentModule($name); $type = $this->moduleSpecs[$name][1]; if (!pradoImportClass($type)) { throw new TModuleNotDefinedException($type); } $module = $this->createComponent($type, $name); if (!$module instanceof TModule) { // will use is_subclass_of since PHP 5.0.3 throw new TModuleNotDefinedException($type); } $module->setUserParameters($this->moduleSpecs[$name][4]); $module->loadConfig($this->moduleSpecs[$name][0]); $module->initProperties(); $this->modules[$name] = $module; $module->onLoad(new TEventParameter()); return $module; }
function detail() { global $viewhelper; using("tag", "meta"); $tag = new Tags(); $meta = new Metas(); $conditions = array(); $viewhelper->setTitle(L("info", "tpl")); $viewhelper->setPosition(L("info", "tpl"), "index.php?do=news"); if (isset($_GET['title'])) { $title = trim($_GET['title']); $res = $this->news->findByTitle($title); $id = $res['id']; } if (isset($_GET['id'])) { $id = intval($_GET['id']); } if (!empty($id)) { $_PB_CACHE['newstype'] = cache_read("type", "newstype"); $this->news->clicked($id); $info = $this->news->read("*", $id); if (empty($info) or !$info) { flash("data_not_exists", '', 0); } if (!empty($info['tag_ids'])) { $the_tags = $tag->getTagsByIds($info['tag_ids'], true); $tmp = null; $info['tag'] = $tag->tag; foreach ($the_tags as $key => $val) { $tmp .= "<a href='" . $this->url(array("module" => "search", "do" => "news", "q" => urlencode($val))) . "'>" . $val . "</a> "; } $info['tag_link'] = $tmp; } if (!empty($info['picture'])) { $info['image'] = pb_get_attachmenturl($info['picture'], '', 'small'); } $info['pubdate'] = df($info['created']); $info['typename'] = $_PB_CACHE['newstype'][$info['type_id']]; $viewhelper->setTitle($info['typename']); $viewhelper->setPosition($info['typename'], $this->url(array("module" => "search", "do" => "news", "typeid" => $info['type_id']))); //seo info $meta_info = $meta->getSEOById($id, 'news', false); empty($meta_info['title']) ? $viewhelper->setTitle($info['title']) : $viewhelper->setTitle($meta_info['title']); empty($meta_info['description']) ? $viewhelper->setMetaDescription($info['content']) : $viewhelper->setMetaDescription($meta_info['description']); if (isset($meta_info['keyword'])) { $viewhelper->setMetaKeyword($meta_info['keyword']); } $viewhelper->setPosition($info['title']); if (!empty($info['require_membertype'])) { $require_ids = explode(",", $info['require_membertype']); if (!empty($pb_userinfo['pb_userid'])) { $membertype_id = $this->news->dbstuff->GetOne("SELECT membertype_id FROM {$tb_prefix}members WHERE id='" . $pb_user['pb_userid'] . "'"); if (!in_array($membertype_id, $require_ids)) { $info['content'] = L("news_membertype_not_allowed", "tpl"); } } else { $info['content'] = L("news_membertype_not_allowed", "tpl"); } } if ($info['type'] == 1) { $info['source'] = L("company_news", "tpl"); $info['content'] = "<a href='" . $info['content'] . "'>" . $info['content'] . "</a>"; } if (!empty($info['picture'])) { $info['image_url'] = pb_get_attachmenturl($info['picture']); } $neighbour_info = $this->news->getNeighbour($id, "id,title"); if (!empty($neighbour_info['prev'])) { $title = pb_lang_split($neighbour_info['prev']['title']); $info['prev_link'] = "<a href='" . $this->url(array("module" => "news", "id" => $neighbour_info['prev']['id'])) . "'>" . $title . "</a>"; $info['prev_title'] = $title; } else { $info['prev_link'] = L("nothing", "tpl"); } if (!empty($neighbour_info['next'])) { $title = pb_lang_split($neighbour_info['next']['title']); $info['next_link'] = "<a href='" . $this->url(array("module" => "news", "id" => $neighbour_info['next']['id'])) . "'>" . $title . "</a>"; $info['next_title'] = $title; } else { $info['next_link'] = L("nothing", "tpl"); } setvar("item", pb_lang_split_recursive($info)); } else { flash(); } setvar("Newstypes", $_PB_CACHE['newstype']); render("detail.default"); }
<?php module("Lepton CMS Blog Stub"); config::def('lepton.cms.blog.defaultblog', 'default'); using('lepton.cms.blog.*');
function __construct() { using('lepton.system.ipc'); }
<?php using('lunit.lunitcase'); using('lepton.math'); interface ILunitStatusCallback { function onCaseBegin($name, $meta); function onCaseEnd(); function onTestBegin($name, $meta); function onTestEnd($status, $message); } abstract class Lunit { private static $cases = array(); public static function register($case) { self::$cases[] = $case; } public static function getCases() { return self::$cases; } } class LunitRunner { private $statuscb = null; private $results = null; private $dblog = null; function setStatusCallback(ILunitStatusCallback $object) { $this->statuscb = $object;
<?php /* * Created on 17-Jan-2005 * */ using('System.Data'); require_once 'svnmanager/global/Security.php'; class DataModule extends TModule { public function onLoad($param) { parent::onLoad($param); require "config.php"; //Set UTF-8 encoding mb_internal_encoding('UTF-8'); //This should prevent te removal of multibyte unicode characters with escapeshellarg if (false == setlocale(LC_CTYPE, "UTF8", $lang)) { die("skip setlocale() failed, unicode characters might fail!\n"); } $this->Database->setDataSourceName($dsn); } public function hasGrants() { $userid = $this->User->getId(); $s_userid = makeSqlString($userid); $result = $this->Database->Execute("SELECT * FROM users WHERE id={$s_userid}"); $fields = $result->fields; if ($fields['repositorygrants'] > 0) { return true; }
<?php using('lepton.net.httprequest'); /** * Xmlrpc utility class, loaded into controllers and libraries as xmlrpc * and provides shorthand functions for creating a new server and client. * * @since 0.2 * @author Christopher Vagnetoft <*****@*****.**> * @see XmlrpcServer * @see XmlrpcClient */ class Xmlrpc { /** * Create and return a new XmlrpcClient object. * * @param string $url The API url * @param string $username The username to authenticate as (optional) * @param string $password The password to authenticate with (optional) * @return XmlrpcClient The client instance */ function createClient($url, $username = null, $password = null) { return new XmlrpcClient($url, $username, $password); } /** * Create and return a new XmlrpcServer object. * * @return XmlrpcServer The server instance */