• Edgel
  • PHP
  • 3.6MB
  • rar
  • 0
  • 1 积分
  • 0
  • 2020-07-03 06:57
Application of a personal portfolio with projects carried out
PHP CSS Parser -------------- [![build status](https://api.travis-ci.org/sabberworm/PHP-CSS-Parser.svg)](https://travis-ci.org/sabberworm/PHP-CSS-Parser) [![HHVM Status](http://hhvm.h4cc.de/badge/sabberworm/php-css-parser.svg)](http://hhvm.h4cc.de/package/sabberworm/php-css-parser) A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output as (optimized) CSS. ## Usage ### Installation using composer Add php-css-parser to your composer.json ```json { "require": { "sabberworm/php-css-parser": "*" } } ``` ### Extraction To use the CSS Parser, create a new instance. The constructor takes the following form: ```php new Sabberworm\CSS\Parser($sText); ``` To read a file, for example, you’d do the following: ```php $oCssParser = new Sabberworm\CSS\Parser(file_get_contents('somefile.css')); $oCssDocument = $oCssParser->parse(); ``` The resulting CSS document structure can be manipulated prior to being output. ### Options #### Charset The charset option is used only if no @charset declaration is found in the CSS file. UTF-8 is the default, so you won’t have to create a settings object at all if you don’t intend to change that. ```php $oSettings = Sabberworm\CSS\Settings::create()->withDefaultCharset('windows-1252'); new Sabberworm\CSS\Parser($sText, $oSettings); ``` #### Strict parsing To have the parser choke on invalid rules, supply a thusly configured Sabberworm\CSS\Settings object: ```php $oCssParser = new Sabberworm\CSS\Parser(file_get_contents('somefile.css'), Sabberworm\CSS\Settings::create()->beStrict()); ``` #### Disable multibyte functions To achieve faster parsing, you can choose to have PHP-CSS-Parser use regular string functions instead of `mb_*` functions. This should work fine in most cases, even for UTF-8 files, as all the multibyte characters are in string literals. Still it’s not recommended to use this with input you have no control over as it’s not thoroughly covered by test cases. ```php $oSettings = Sabberworm\CSS\Settings::create()->withMultibyteSupport(false); new Sabberworm\CSS\Parser($sText, $oSettings); ``` ### Manipulation The resulting data structure consists mainly of five basic types: `CSSList`, `RuleSet`, `Rule`, `Selector` and `Value`. There are two additional types used: `Import` and `Charset` which you won’t use often. #### CSSList `CSSList` represents a generic CSS container, most likely containing declaration blocks (rule sets with a selector) but it may also contain at-rules, charset declarations, etc. `CSSList` has the following concrete subtypes: * `Document` – representing the root of a CSS file. * `MediaQuery` – represents a subsection of a CSSList that only applies to a output device matching the contained media query. To access the items stored in a `CSSList` – like the document you got back when calling `$oCssParser->parse()` –, use `getContents()`, then iterate over that collection and use instanceof to check whether you’re dealing with another `CSSList`, a `RuleSet`, a `Import` or a `Charset`. To append a new item (selector, media query, etc.) to an existing `CSSList`, construct it using the constructor for this class and use the `append($oItem)` method. #### RuleSet `RuleSet` is a container for individual rules. The most common form of a rule set is one constrained by a selector. The following concrete subtypes exist: * `AtRuleSet` – for generic at-rules which do not match the ones specifically mentioned like @import, @charset or @media. A common example for this is @font-face. * `DeclarationBlock` – a RuleSet constrained by a `Selector`; contains an array of selector objects (comma-separated in the CSS) as well as the rules to be applied to the matching elements. Note: A `CSSList` can contain other `CSSList`s (and `Import`s as well as a `Charset`) while a `RuleSet` can only contain `Rule`s. If you want to manipulate a `RuleSet`, use the methods `addRule(Rule $oRule)`, `getRules()` and `removeRule($mRule)` (which accepts either a Rule instance or a rule name; optionally suffixed by a dash to remove all related rules). #### Rule `Rule`s just have a key (the rule) and a value. These values are all instances of a `Value`. #### Value `Value` is an abstract class that only defines the `render` method. The concrete subclasses for atomic value types are: * `Size` – consists of a numeric `size` value and a unit. * `Color` – colors can be input in the form #rrggbb, #rgb or schema(val1, val2, …) but are always stored as an array of ('s' => val1, 'c' => val2, 'h' => val3, …) and output in the second form. * `CSSString` – this is just a wrapper for quoted strings to distinguish them from keywords; always output with double quotes. * `URL` – URLs in CSS; always output in URL("") notation. There is another abstract subclass of `Value`, `ValueList`. A `ValueList` represents a lists of `Value`s, separated by some separation character (mostly `,`, whitespace, or `/`). There are two types of `ValueList`s: * `RuleValueList` – The default type, used to represent all multi-valued rules like `font: bold 12px/3 Helvetica, Verdana, sans-serif;` (where the value would be a whitespace-separated list of the primitive value `bold`, a slash-separated list and a comma-separated list). * `CSSFunction` – A special kind of value that also contains a function name and where the values are the function’s arguments. Also handles equals-sign-separated argument lists like `filter: alpha(opacity=90);`. #### Convenience methods There are a few convenience methods on Document to ease finding, manipulating and deleting rules: * `getAllDeclarationBlocks()` – does what it says; no matter how deeply nested your selectors are. Aliased as `getAllSelectors()`. * `getAllRuleSets()` – does what it says; no matter how deeply nested your rule sets are. * `getAllValues()` – finds all `Value` objects inside `Rule`s. ## To-Do * More convenience methods [like `selectorsWithElement($sId/Class/TagName)`, `attributesOfType($sType)`, `removeAttributesOfType($sType)`] * Real multibyte support. Currently only multibyte charsets whose first 255 code points take up only one byte and are identical with ASCII are supported (yes, UTF-8 fits this description). * Named color support (using `Color` instead of an anonymous string literal) ## Use cases ### Use `Parser` to prepend an id to all selectors ```php $sMyId = "#my_id"; $oParser = new Sabberworm\CSS\Parser($sText); $oCss = $oParser->parse(); foreach($oCss->getAllDeclarationBlocks() as $oBlock) { foreach($oBlock->getSelectors() as $oSelector) { //Loop over all selector parts (the comma-separated strings in a selector) and prepend the id $oSelector->setSelector($sMyId.' '.$oSelector->getSelector()); } } ``` ### Shrink all absolute sizes to half ```php $oParser = new Sabberworm\CSS\Parser($sText); $oCss = $oParser->parse(); foreach($oCss->getAllValues() as $mValue) { if($mValue instanceof CSSSize && !$mValue->isRelative()) { $mValue->setSize($mValue->getSize()/2); } } ``` ### Remove unwanted rules ```php $oParser = new Sabberworm\CSS\Parser($sText); $oCss = $oParser->parse(); foreach($oCss->getAllRuleSets() as $oRuleSet) { $oRuleSet->removeRule('font-'); //Note that the added dash will make this remove all rules starting with font- (like font-size, font-weight, etc.) as well as a potential font-rule $oRuleSet->removeRule('cursor'); } ``` ### Output To output the entire CSS document into a variable, just use `->render()`: ```php $oCssParser = new Sabberworm\CSS\Parser(file_get_contents('somefile.css')); $oCssDocument = $oCssParser->parse(); print $oCssDocument->render(); ``` If you want to format the output, pass an instance of type `Sabberworm\CSS\OutputFormat`: ```php $oFormat = Sabberworm\CSS\OutputFormat::create()->indentWithSpaces(4)->setSpaceBetweenRules("\n"); print $oCssDocument->render($oFormat); ``` Or use one
    • DirBuster-1.0-RC1.zip
    • sonstruct-priority.rar
      VB to achieve real multi-threaded operation of the code can go
    • pNews System-开源
      pNews系统是用于提交要发布在网站上的新闻的系统,当前与phpBB交互以创建指向论坛帖子(也使用新闻系统创建)的动态链接。 然后,这些链接与
    • Well-Me-wellness-app
      好吧我 Well Me是一种健康跟踪器,用户可以在其中跟踪其健康目标并找到灵感。 描述 输入他们的数据和个人目标后,Well Me会计算出用户建议的卡路里摄入量和理想体重。 用户每天记录他们的结果,并获得健康评分以及...
    • ConsultComm Project Timekeeper-开源
      Consultant Communicator (ConsultComm) 是一个用 Java 编写的小型、轻量级、独立于平台的程序,它允许管理多个项目、客户或任务的任何人有效地准确跟踪他们在每个项目上花费的时间。
    • Luau Autoupdate Library-开源
    • alexa-skills-list-master.zip
      校招java笔试题Alexa 技能列表 所有可用 Alexa 技能的完整列表 可用技能总数: 5817 此技能没有示例交互。 空值 Alexa,开始我们欢呼吧 Alexa 在标志性的“We Are”欢呼声中引领您。 Alexa,打开 ...向
    • ph-commons-master.zip
      酸碱度 Java 1.8+库包含大多数ph- *项目中所需的大量实用程序类。 版本6.x包含重大更改,并且几乎发布了所有其他项目以反映6.x的更改。 版本7不存在。 已重新设计版本8.x,以使其与JDK 8最佳配合。...
    • 11-ghuloum.zip
      我们构造的编译器接受方案编程的一个大子集 语言并生成英特尔x86的汇编代码 架构,个人计算的主导架构。这个 编译器的开发分为许多小的增量 台阶。每一步都产生一个完全工作的编译器 展开方案子集。...
    • android从bootloader到launcher启动流程整理
      讲述android 开机流程 从boot rom---bootloader---init--zygote---systemserver---ams 并附上自己整理的每个流程的流程图 ,清晰熟悉android 启动流程